[NSFW] WooCommerce AJAX add to cart don’t work for variable products
-
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.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘[NSFW] WooCommerce AJAX add to cart don’t work for variable products’ is closed to new replies.