删除某些字段后,标签和值未正确显示在my-account / edit-address /中

时间:2019-02-25 21:09:02

标签: php wordpress woocommerce

在Woocommerce中,我已将以下代码添加到主题的functions.php文件中,以删除/ my-account / edit-address / billing中的zip / state字段:

 add_filter('woocommerce_address_to_edit', 'reorder_woocommerce_address_fields', 10, 2);
function reorder_woocommerce_address_fields( $address, $load_address) {
    $new_address['billing_first_name'] = $address['billing_first_name'];
    $new_address['billing_last_name'] = $address['billing_last_name'];
    $new_address['billing_email'] = $address['billing_email'];
    $new_address['billing_phone'] = $address['billing_phone'];

    $new_address['billing_email'] = array(
        'label'     => __('Email', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-first'),
    );

    $new_address['billing_phone'] = array(
        'label'     => __('Phone', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-last'),
        'clear'     => true
    );

    $new_address['billing_company'] = $address['billing_company'];
    $new_address['billing_country'] = $address['billing_country'];
      $new_address['billing_city'] = $address['billing_city'];
    $new_address['billing_address_1'] = $address['billing_address_1'];

    return $new_address;
}

它基于Customizing my-account addresses fields in Woocommerce 3答案代码,并删除了字段...

但是仍然有一条错误消息,提示状态和邮政编码字段为必填。所以我添加了这个:

 add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
 function custom_override_default_address_fields( $address_fields ) {
      global $woocommerce;
      $country = $woocommerce->customer->get_country();
      if($country !== 'US'){
         $address_fields['state']['required'] = false;
         $address_fields['postcode']['required'] = false;
      }
      return $address_fields;
 }

现在地址通常可以保存,但是当我重定向到/ my-account / edit-address /时,只能看到以下内容:

enter image description here

其中:
康斯坦丁-是billing_first_name
Berulava-是billing_last_name
Odelia Studio-是billing_company
地高米-是billing_address_1
第比利斯-是billing_city

我没有看到标签,某些字段也丢失了。

关于做什么的任何建议?

0 个答案:

没有答案