Update_order_review () when a button is clicked

I have a custom button on my checkout page, after which I add the product to the cart through AJAX.

JS:

$('#add_domain_product').on('click', function() { $.ajax({ url: Ajax.ajaxurl, type: "POST", data: { action: 'add_domain_product', }, success: function (data, status, xhr) { // update command is executed. console.log(data); } }); }) 

PHP:

 add_action('wp_ajax_add_domain_product', 'bs_add_domain_product'); function bs_add_domain_product() { global $woocommerce; $woocommerce->cart->add_to_cart('633'); exit(); } 

After that I will need to update the order overview, so it will also display my newly added product. How can i do this?

+6
source share
2 answers

All you have to do is call the trigger on the body to refresh the cart.

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

This will automatically call all subsequent AJAX calls necessary to update the cart information, including order verification.

+16
source

On the Checkout page:

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

In the basket:

 jQuery(document.body).trigger("wc_update_cart"); 
+1
source

Source: https://habr.com/ru/post/980120/


All Articles