3

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

MiraTech
  • 1,108
  • 18
  • 35

3 Answers3

3

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;
}
Purvik Dhorajiya
  • 4,662
  • 3
  • 34
  • 43
  • How to get the data of the field for displaying it on the order details? – svelandiag Jul 01 '20 at 02:00
  • @svelandiag try this https://www.businessbloomer.com/woocommerce-easily-get-order-info-total-items-etc-from-order-object/ or https://stackoverflow.com/questions/39401393/how-to-get-woocommerce-order-details – Purvik Dhorajiya Jul 01 '20 at 07:56
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;
}
MiraTech
  • 1,108
  • 18
  • 35
0

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


MrSwed
  • 559
  • 8
  • 15