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?
From the dashboard menu, click on the Appearance Menu > Theme Editor Menu. When the theme editor page is opened, look for the theme functions file with the extension functions. php. Open this functions file to add the function to refresh the WooCommerce checkout page automatically.
AJAX's use on the one page checkout enables the checkout to function so your customers do not have to wait for a new page to load or the existing page to reload.
This works:
jQuery(document.body).trigger("update_checkout");
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With