Skip to main content
Login Join
Snippet · JavaScript

Update/Refresh WooCommerce Checkout Form

Shared by Mohamed Amine Abla · June 4, 2026

20 views
1 upvote
Back to Snippets

This script listens for a specific DOM event (like a click or change) on an element. When triggered, it sends an AJAX request to the server to update checkout data. If the server successfully processes the request, the script fires WooCommerce’s native update_checkout event to automatically refresh the checkout form totals and fragments without a page reload.

$('selector').on('event', function() {

     $.ajax({
            url: wp_ajax.ajax_url, 
            type: 'POST',
            dataType: 'json',
            data: {
                action: 'update_checkout_function'
            },
            success: function(response) {
                if (response.success) {
                    console.log(response);
                    
                    $('body').trigger('update_checkout');
                } else {
                    console.error(response.data);
                }
            },
            error: function(error) {
                console.error(error);
            }
        });
}

0 comments