Unable to add a variation to cart using jQuery, the parent product is added, but not the varitation.
For example, I specified one of T-shirt variations (blue) with price of 45$ but at the end, the parent is added with price of 30$
Cart should show: T-shirt – Blue 45$
Instead it shows: T-shirt 30$
How to accomplish this with jQuery?
My code so far:
jQuery(document).ready(function($) {
$(document.body).on('click', '#button', function(e) {
const data = {
product_id: 592,
quantity: 2,
variation_id: 1017,
};
$.ajax({
type: 'POST',
url: wc_add_to_cart_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'add_to_cart' ),
data: data,
success: function(res) {
console.log('added');
},
});
});
});
New contributor
Becker Armata is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.