繁体   English   中英

在帐单地址 woocommerce 处添加新字段

[英]Add new fields at the billing address woocommerce

我想在我的网站上编辑我的账单地址,我需要在我的帐户页面中添加删除一些其他人,我应该编辑哪些代码?

提前谢谢

您能否检查下面的代码,您可以添加新的自定义字段示例。

add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );

function custom_woocommerce_billing_fields( $fields ) {

   $fields['billing']['billing_options'] = array(
    'label'       => __('Custom Field', 'woocommerce'),             // Add custom field label
    'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'),  // Add custom field placeholder
    'required'    => false,             // if field is required or not
    'clear'       => false,             // add clear or not
    'type'        => 'text',                // add field type
    'class'       => array('own-css-name')      // add class name
    );

 return $fields;
}

要删除现有字段,例如国家/地区:

add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
function custom_override_billing_fields( $fields ) {
  unset($fields['billing_country']);
  return $fields;
}

也许最好的方法是使用woocommerce_default_address_fields - 是吗? 例如#5447232


add_filter( 'woocommerce_default_address_fields', 'add_MyNewOption_address' );

function add_MyNewOption_address( $fields ) {

   $fields['MyNewOption'] = array(
    'label'       => __('Custom Field', 'woocommerce'),             // Add custom field label
    'placeholder' => _x('Custom Field', 'placeholder', 'woocommerce'),  // Add custom field placeholder
    'required'    => false,             // if field is required or not
    'clear'       => false,             // add clear or not
    'type'        => 'text',                // add field type
    'class'       => array('own-css-name')      // add class name
    );

 return $fields;
}


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM