Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 422
Magnus Pilegaard Avatar asked Nov 30 '16 22:11

Magnus Pilegaard


People also ask

How to refresh checkout page WooCommerce?

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.

What is AJAX checkout?

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.


2 Answers

This works:

jQuery(document.body).trigger("update_checkout");
like image 69
Hamid Mohayeji Avatar answered Sep 29 '22 06:09

Hamid Mohayeji


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

like image 41
DavSev Avatar answered Sep 29 '22 07:09

DavSev