微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

WooCommerce 运输文件需要状态

如何解决WooCommerce 运输文件需要状态

我正在使用下面的功能根据客户是否选择本地取货来显示/隐藏结帐的送货地址部分。

它工作正常,但是运输部分中的某些字段是必需的,因此如果选择本地运输,结帐将不起作用。

如果选择本地取货,有没有办法让这些字段不再需要?

.git

解决方法

/* only hide shipping section using css/jquery is not the solution. you must need to remove fields as per your requirement */

/* please Add the following code to your child theme functions.php file */ 

  add_filter( 'woocommerce_checkout_fields','change_shipping_field_optional');

  function change_shipping_field_optional( $fields ) {
 
    $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
    $shipping_pickup = $chosen_methods[0];
    
    if ($shipping_pickup == 'local_pickup:4') // here your shipping rate ID
    {
       /* add fields here as per your requirement */

        $fields['shipping_first_name']['required'] = false;
        $fields['shipping_last_name']['required'] = false;
        $fields['shipping_company']['required'] = false;
        $fields['shipping_country']['required'] = false;
        $fields['shipping_address_1']['required'] = false;
        $fields['shipping_address_2']['required'] = false;
        $fields['shipping_city']['required'] = false;
        $fields['shipping_state']['required'] = false;
        $fields['shipping_postcode']['required'] = false;
        
        unset($fields['shipping']['shipping_first_name']);
        unset($fields['shipping']['shipping_last_name']);
        unset($fields['shipping']['shipping_company']);
        unset($fields['shipping']['shipping_country']);
        unset($fields['shipping']['shipping_address_1']);
        unset($fields['shipping']['shipping_address_2']);
        unset($fields['shipping']['shipping_city']);
        unset($fields['shipping']['shipping_state']);
        unset($fields['shipping']['shipping_postcode']);
        
     }
        return $fields;
  }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。