Add new fields at the billing address woocommerce

 ̄綄美尐妖づ 提交于 2021-02-10 05:51:32

问题


I want to edit my billing address at my website, where i need to add and delete some others in my account page, which code shall I edit?

Thank you in advanced


回答1:


Can you please check below code you can add new custom field example.

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;
}



回答2:


To delete an existing field, country for example:

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



回答3:


maybe the best way use woocommerce_default_address_fields - is it ? for example as #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;
}




来源:https://stackoverflow.com/questions/37729524/add-new-fields-at-the-billing-address-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!