• Hi guys,

    In order to customise my checkout page, I used this tutorial:
    https://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/

    It helped me to remove some unnecessary fields on the checkout page (I already localised the theme into my language).
    [img]https://s11.postimage.org/v08ydp6v7/Screen_Shot_2012_10_02_at_12_04_22_AM.png[/img]

    However, it didn’t remove any fields on the Edit Address page (My account -> Edit Address).
    [img]https://s13.postimage.org/v74e0aduv/Screen_Shot_2012_10_02_at_12_05_58_AM.png[/img]

    I looked for the answer throughout the Internet but nothing found. I also found the file my-address.php in wp-content/plugins/woocommerce/templates/myaccount. I think it would help to remove unnecessary fields on the Edit Address page but I don’t know how to edit the file (sorry I’m not familiar with these coding stuff).

    Can you guys help me to solve this problem?

    Thank you in advance for any help that you can provide.

Viewing 13 replies - 16 through 28 (of 28 total)
  • Try this:

    // woocommerce remove checkout form fields
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    function custom_override_checkout_fields( $fields ) {
         unset($fields['billing']['billing_country']);
         unset($fields['billing']['billing_company']);
         unset($fields['billing']['billing_address_1']);
         unset($fields['billing']['billing_address_2']);
         unset($fields['billing']['billing_postcode']);
         unset($fields['billing']['billing_city']);
    
         return $fields;
    }

    The following code will remove all fields in the checkout page, shipping and billing fields (also in “Edit Address”). It will only show the First Name, Last Name, Email and Phone. The Phone field will not be required to fill out.

    Add this to your functions.php

    /* Remove Woocommerce User Fields */
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
    add_filter( 'woocommerce_shipping_fields' , 'custom_override_shipping_fields' );
    
    function custom_override_checkout_fields( $fields ) {
      unset($fields['billing']['billing_state']);
      unset($fields['billing']['billing_country']);
      unset($fields['billing']['billing_company']);
      unset($fields['billing']['billing_address_1']);
      unset($fields['billing']['billing_address_2']);
      unset($fields['billing']['billing_postcode']);
      unset($fields['billing']['billing_city']);
      unset($fields['shipping']['shipping_state']);
      unset($fields['shipping']['shipping_country']);
      unset($fields['shipping']['shipping_company']);
      unset($fields['shipping']['shipping_address_1']);
      unset($fields['shipping']['shipping_address_2']);
      unset($fields['shipping']['shipping_postcode']);
      unset($fields['shipping']['shipping_city']);
      return $fields;
    }
    function custom_override_billing_fields( $fields ) {
      unset($fields['billing_state']);
      unset($fields['billing_country']);
      unset($fields['billing_company']);
      unset($fields['billing_address_1']);
      unset($fields['billing_address_2']);
      unset($fields['billing_postcode']);
      unset($fields['billing_city']);
      return $fields;
    }
    function custom_override_shipping_fields( $fields ) {
      unset($fields['shipping_state']);
      unset($fields['shipping_country']);
      unset($fields['shipping_company']);
      unset($fields['shipping_address_1']);
      unset($fields['shipping_address_2']);
      unset($fields['shipping_postcode']);
      unset($fields['shipping_city']);
      return $fields;
    }
    /* End - Remove Woocommerce User Fields */
    
    /* Make Woocommerce Phone Field Not Required  */
    add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 );
    function wc_npr_filter_phone( $address_fields ) {
    	$address_fields['billing_phone']['required'] = false;
    	return $address_fields;
    }
    /* End - Make Woocommerce Phone Field Not Required  */

    See the final result here: MyClassiPress.com/

    Cheers

    This is really helpful, and I’ve used some of the code from this thread to add an extra customer details field to my checkout page (for the customer’s tax registration number).

    But what I can’t seem to find out, is how to have this extra field also show up on the admin side, in the user – profile area, and also when the user registers. If I could include it here then that would be really ideal.

    Also, my next task is to get this extra field to print in the order email, but one thing at a time!

    hi i have unique problem i want my checkout page to display a label in city and statefield

    Hey Folks….is there any way to make the coupon code required? I want to give all my clients a coupon code on before the check out and make it mandatory before they move to checkout on the cart screen.

    Thank you samwan, I managed to remove field on the Edit Address page. But now I have to modifiy the label each field. How can I do that?

    I tried to put this code to change the label and placeholder

    $fields[‘billing’][‘billing_first_name’][‘label’] = ‘Nama Lengkap’;
    $fields[‘billing’][‘billing_first_name’][‘placeholder’] = ‘Nama Lengkap’;

    I put that code under

    function custom_override_billing_fields( $fields ) {

    That’s not working to modify the Edit Address page. Please help me?
    Any help would be much appreciated. Thank you

    @ivan

    In your code, just remove ['billing'] or ['shipping'] after $fields

    add_filter( 'woocommerce_shipping_fields' , 'custom_override_shipping_fields' );
    function custom_override_shipping_fields( $fields ) {
        $fields['shipping_address_1']['label'] = 'Shipping Location in the Philippines';
        $fields['shipping_address_2'] = array(
    	'placeholder' => "Subdivision / Barangay / Municipality",
    	'required' => true
    	);
        $fields['shipping_city'] = array(
    	'label' => "City",
    	'placeholder' => "City",
            'required' => true
    	);
    
    return $fields;
    }

    Screenshot of the example above

    Hello @samwan i just used your method to edit the checkout page and addresses, but i am getting an error via placing the order that these fields are required even though i dont have these strange letters as fields and i have no idea what they represent:

    J is a required field.
    B is a required field.
    N is a required field.
    A is a required field.
    S is a required field.
    H is a required field.
    H is a required field.

    check this screen shot

    any idea how to solve this ?

    Sorry this is the correct screenshot link:
    click here

    samwan Great! Works, Thanks!

    Just stumbled across this. Thanks to c_turnbull and spybubblegum for the input here. Helped me out loads guys.

    Hi People, I am using Sistina theme with woocommerce v2.0.14
    1. Tried the below which successfully got rid of the VAT/SSN field but also broke the form layout.

    // Hook in
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    // Our hooked in function - $fields is passed via the filter!
    function custom_override_checkout_fields( $fields ) {
    unset($fields['order']['order_comments']);
    
    return $fields;
    }

    Can anyone advise as to how to stop the form layout going wrong….?

    2. I would also like to make certain fields mandatory – some of the fields have default red asterisk however they do not seem to be actually mandatory… https://www.w-i-p.net/aidkits/

    I am on a steepish learning curve so please be gentle.

    Thanks in advance WP people ??

Viewing 13 replies - 16 through 28 (of 28 total)
  • The topic ‘[WooCommerce] Remove fields on Edit Address’ is closed to new replies.