You can create same controller as default addToCart controller.
public function execute()
{
$currentStore = $this->storeManager->getStore();
$baseUrl = $currentStore->getBaseUrl();
$post = $this->getRequest()->getPostValue();
$option=array();
foreach($post as $key => $val) {
if($key =='p_id' || $key =='qty' || $key == 'customoption_id' || $key == 'product-custom-option')
{
continue;
}
else{
$option[$key] = $val;
}
}
$productid = $post['p_id'];
$_product = $this->_productRepositoryInterface->getById($productid);
if ($_product->hasOptions()){
$options = $_product->getOptions();
$customoptions = array();
$customoptions[$post['customoption_id']] = $post['product-custom-option'];
$params = array (
'product' => $_product->getId(),
'qty' => $post['qty'],
'price' => $_product->getPrice(),
'options' => $customoptions,
'super_attribute'=>$option
);
}else{
$params = array (
'product' => $_product->getId(),
'qty' => $post['qty'],
'price' => $_product->getPrice(),
'super_attribute'=>$option
);
}
$this->_cart->addProduct($_product, $params);
$this->_cart->save();
$this->messageManager->addSuccess(__("You added ".$_product->getName()." to your shopping cart."));
//$this->_redirect('checkout/cart/index');
}