简体   繁体   中英

Add new fields at the billing address woocommerce

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

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

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

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


The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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