Magnus Pilegaard
Magnus Pilegaard

Reputation: 393

Woocommerce update checkout ajax

As i'm using a onepager for 1 product i'd like to make use of wordpress ajax to update the checkout on site, when i'm adding the product to the cart. The product add to cart button is already ajax.

I have tried the: $('body').trigger('update_checkout');, but it didnt work. It's inside an .on click function. I suspect that the checkout updater runs before the add to cart can get to save and therefore doesn't have anything to read from. This is just a theory though.

How do i go about this?

Upvotes: 8

Views: 27736

Answers (3)

DavSev
DavSev

Reputation: 1111

Try this one:

jQuery('body').trigger('update_checkout');

You can not use dollar sign $ to call jQuery in wordpress, instead you must use the string jQuery

Have a look at tip 5 in this web page: 5 Tips for using jquery with wordpress:

It is important to know that the version of jQuery that comes with WordPress automatically calls the jQuery.noConflict(); function, which gives control of the $ variable back to whichever library first implemented it. If you are loading a different copy of jQuery, you'll need to manually call jQuery.noConflict();, if necessary, from one of your JavaScript files.

The explanation is taken from https://stackoverflow.com/a/15132734/3471458

Upvotes: 2

Hamid Mohayeji
Hamid Mohayeji

Reputation: 4295

This works:

jQuery(document.body).trigger("update_checkout");

Upvotes: 17

Fredrik Borggren
Fredrik Borggren

Reputation: 107

You can try the following trigger instead.

$( document ).trigger( 'wc_update_cart' );

Best regards

Upvotes: 0

Related Questions