I have a custom button on my checkout page, on click I'm adding a product to cart via 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'd need to refresh the order review, so it displays my newly added product also. How can I do that?
All you need to do is call a trigger on the body to update the cart.
$( 'body' ).trigger( 'update_checkout' );
This will automatically call all the subsequent AJAX calls needed to refresh the cart information, including the order review.
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