On country change ajax update checkout for shipping in Woocommerce

前端 未结 1 1915
梦如初夏
梦如初夏 2021-01-07 07:10

I\'m looking for a way to update order review (shipping price) when client change country on checkout page. I want to use jQuery. but wc_checkout_params wc_

相关标签:
1条回答
  • 2021-01-07 08:13

    Normally woocommerce do it itself, and nothing is needed…

    But you can try the following instead, that should work in Woocommerce 3+ versions:

    add_action('wp_footer', 'billing_country_update_checkout', 50);
    function billing_country_update_checkout() {
        if ( ! is_checkout() ) return;
        ?>
        <script type="text/javascript">
        jQuery(function($){
            $('select#billing_country, select#shipping_country').on( 'change', function (){
                var t = { updateTimer: !1,  dirtyInput: !1,
                    reset_update_checkout_timer: function() {
                        clearTimeout(t.updateTimer)
                    },
                    trigger_update_checkout: function() {
                        t.reset_update_checkout_timer(), t.dirtyInput = !1,
                        $(document.body).trigger("update_checkout")
                    }
                };
                $(document.body).trigger('update_checkout');
                console.log('Event: update_checkout');
            });
        });
        </script>
        <?php
    }
    

    Code goes in function.php file of your active child theme (or active theme). Tested and works.

    0 讨论(0)
提交回复
热议问题