【问题标题】:Woocommerce checkout page reload after change shipping method更改运输方式后 Woocommerce 结帐页面重新加载
【发布时间】:2019-10-30 12:57:22
【问题描述】:

一旦我在结帐页面上更改了运送选项,我想显示/隐藏一些字段,但是一旦我手动重新加载页面,它就可以工作,然后我添加了一个 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;
}

但这对我不起作用,你能指导我吗?

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    在应用更改之前刷新页面。 updated_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>
    

    【讨论】:

      猜你喜欢
      • 2021-04-21
      • 1970-01-01
      • 2013-06-21
      • 2022-08-24
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 2015-06-28
      • 1970-01-01
      相关资源
      最近更新 更多