I have a JavaScript variable that I want to use in a JSON format.
var add = mixItems[i][0] + "," + mixItems[i][1];
jQuery.getJSON("wp-content/plugins/proteinmixer/php/addtocart.php" , function(data){
});
Here is the PHP code:
require_once('../../../../wp-blog-header.php');
header('Content-Type:application/json');
global $woocommerce;
$productId = 66;
$quantity = 10;
//$add = $productId.",".$quantity."";
//$add = add;
$addtocart = $woocommerce->cart->add_to_cart($add);
echo json_encode($addtocart);
We need to include the variable ADD in the JSON data.