var data = {
action: 'woocommerce_ajax_add_to_cart',
product_id: "23716",
product_sku: 'MUV–SMO6-50ML-EM',
variation_id: "23718",
variation: {
'attribute_pa_volume': '50ml',
},
quantity: '1',
};
$.ajax({
type: 'post',
url: '/?wc-ajax=add_to_cart',
data: data,
beforeSend: function (response) {
console.log('1')
$(".btn-primary").removeClass('added').addClass('loading');
},
complete: function (response) {
$(".btn-primary").addClass('added').removeClass('loading');
},
success: function (response) {
$(document.body).trigger('added_to_cart', [response.fragments, response.cart_hash]);
},
});
Hello, here's the code I'm using to add a product to the cart with woocommerce_ajax_add_to_cart, this works perfectly for a product without variations but it's impossible to add the variation. The product I'm adding has two variations (20ml and 50ml), and each time it adds the product with the 20ml variation corresponding to the variation_id 23717 instead of 23718.
What is the problem with my code ? Thanks.
I want to be able to add a product with variations using this ajax function.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/zv18UXq
Comments
Post a Comment