I'm trying to add products to the cart in woomerce, but am getting a persistent error Uncaught ReferenceError: wc_add_to_cart_params is not defined
.
Have used this approach many times before without issue, has wc_add_to_cart_params been removed from woomerce? If so what is the replacement?
My code is as follows:
var productId = form.find('input[name=product_id]').val();
var variationId = form.find('input[name=variation_id]').val();
var qty = form.find('input[name=qty]').val();
// Data array
var data = {
action: 'woomerce_ajax_add_to_cart',
product_id: productId,
variation_id: variationId,
quantity: qty,
};
// Ajax function
$.ajax({
type: 'post',
url: wc_add_to_cart_params.ajax_url,
data: data,
});
Thanks
I'm trying to add products to the cart in woomerce, but am getting a persistent error Uncaught ReferenceError: wc_add_to_cart_params is not defined
.
Have used this approach many times before without issue, has wc_add_to_cart_params been removed from woomerce? If so what is the replacement?
My code is as follows:
var productId = form.find('input[name=product_id]').val();
var variationId = form.find('input[name=variation_id]').val();
var qty = form.find('input[name=qty]').val();
// Data array
var data = {
action: 'woomerce_ajax_add_to_cart',
product_id: productId,
variation_id: variationId,
quantity: qty,
};
// Ajax function
$.ajax({
type: 'post',
url: wc_add_to_cart_params.ajax_url,
data: data,
});
Thanks
Share edited Oct 3, 2020 at 2:13 LoicTheAztec 255k24 gold badges397 silver badges443 bronze badges asked Oct 1, 2020 at 22:57 dungey_140dungey_140 2,8029 gold badges41 silver badges75 bronze badges2 Answers
Reset to default 6In case this es up for anyone else, it appears the add-to-cart.min.js
only loads if 'Enable AJAX add to cart buttons on archives' is enabled in the WC settings. This resolves the issue for me.
Your syntax is correct but the point is from where it is called. If it is a external js file then enqueue it in footer.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742291889a4416348.html
评论列表(0条)