Search code examples
phpwordpresswoocommercecheckoutshipping-method

WooCommerce Shipping zones based on state Ajax issue


I have a problem with the shipping methods in WooCommerce checkout page, I have set the shipping depending on the state zone.

But when I test on checkout, and try to change the state, the shipping price doesn't change, as you can see in the screenshot below:

screen

On the other hand, when I refresh the page, the price change, so I think the problem comes from Ajax.

Can someone orient me to fixe the problem?


Solution

  • You could try adding the update_totals_on_change class to the field that will have to activate the update of the cart total via Ajax.

    In my example I added it to the billing_state field.

    // adds the "update_totals_on_change" class to the "billing_state" field
    add_filter( 'woocommerce_checkout_fields' , 'bevingrosso_add_custom_address_field_woocommerce', 99 );
    function bevingrosso_add_custom_address_field_woocommerce( $fields ) {
        $fields['billing']['billing_state']['class'] = array( 'update_totals_on_change' );
        return $fields;
    }
    

    The code has been tested and works. Add it to your active theme's functions.php.