Wordpress 更改配送方式后重新加载Woocommerce签出页面

Wordpress 更改配送方式后重新加载Woocommerce签出页面,wordpress,woocommerce,Wordpress,Woocommerce,一旦我更改了签出页面上的配送选项,我想显示/隐藏一些字段,但在我手动重新加载页面后,它就起作用了,然后我添加了一个jquery代码来重新加载页面- jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() { 完整代码- <?php // Add custom Theme Functions here add_filter('woocommerce_checkout_fields',

一旦我更改了签出页面上的配送选项,我想显示/隐藏一些字段,但在我手动重新加载页面后,它就起作用了,然后我添加了一个jquery代码来重新加载页面-

jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
完整代码-

<?php
// Add custom Theme Functions here


add_filter('woocommerce_checkout_fields', 'xa_remove_billing_checkout_fields');

function xa_remove_billing_checkout_fields($fields) {
     $first_shipping_method ='free_shipping:1'; // Set the desired shipping method to hide the checkout field(s).
     $second_shipping_method ='free_shipping:2'; // Set the desired shipping method to hide the checkout field(s).
     $third_shipping_method ='local_pickup:3'; // Set the desired shipping method to hide the checkout field(s).

    global $woocommerce;
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping = $chosen_methods[0];

    if ($chosen_shipping == $first_shipping_method || $chosen_shipping == $third_shipping_method) {
        unset($fields['billing']['billing_address_1']);
        unset($fields['billing']['billing_address_2']);
    }
    if ($chosen_shipping == $second_shipping_method || $chosen_shipping == $third_shipping_method) {
        unset($fields['billing']['billing_pick_up']);
    }

    ?>

    <script type="text/javascript">
         jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
            var val = jQuery( this ).val();
            if (val) {
                  location.reload();
               }
         });
    </script>

    <?php
    return $fields;
}

jQuery('form.checkout')。关于('change','input[name^=“shipping_method”]”,函数(){
var val=jQuery(this.val();
if(val){
location.reload();
}
});

在应用更改之前,将刷新页面。
updated\u checkout
事件运行后重新启动

<script type="text/javascript">
    let isRefreshPage = false;
    jQuery('form.checkout').on('change','input[name^="shipping_method"]',function() {
        var val = jQuery( this ).val();
        if (val) {
            isRefreshPage = true;
        }
    });
     
    jQuery('body').on('updated_checkout', function(){
        if (isRefreshPage) {
            location.reload();
        }
    });
</script>

让isRefreshPage=false;
jQuery('form.checkout')。关于('change','input[name^=“shipping_method”]”,函数(){
var val=jQuery(this.val();
if(val){
isRefreshPage=true;
}
});
jQuery('body')。在('updated_checkout',function()上{
如果(isRefreshPage){
location.reload();
}
});