WordPress.org

Ready to get started?Download WordPress

Forums

[WooCommerce] Remove fields on Edit Address (28 posts)

  1. trongtien88
    Member
    Posted 1 year ago #

    Hi guys,

    In order to customise my checkout page, I used this tutorial:
    http://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]http://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]http://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.

  2. ndoremieux
    Member
    Posted 1 year ago #

    you can edit the file from your dashboard by going to appearance/editor and then select the file from the list on the right, but you need to keep in mind that if you update the theme you will loose your changes, you should never modify theme files unless you keep track of your changes and you apply them again everytime you update the theme.

    Nathalie

  3. trongtien88
    Member
    Posted 1 year ago #

    Hi Nathalie

    Thank you for your response. But I'm afraid that you misunderstood my question. I'm sorry if my previous explanation is too bad.

    I will give you more details this time. I used woocommerce plugin for setting up shop on my website. Woocommerce plugin allows customers to register on my website and buying stuff. Registered customers can edit their billing/shipping address info in their account dashboard. The default billing/shipping info include these fields: First Name, Last name, Company, Adddress 1&2, Phone, Email, Country, City/State. Now I want to remove some fields such as Address 2 and Company.

    This tutorial show me how to remove these fields on Check Out page: http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-hooks-and-filters/
    And I successfully removed Address 2 and Company fields on Check Out page. But it doesn't work on the Edit Address page.

    Therefore, how can I remove these fields on Edit Address page like I did on Check Out page?

  4. Murray644
    Member
    Posted 1 year ago #

    Trongtien,

    Been trying to delete a few things from checkout with no luck, used the tutorial you posted. Where did you place this:

    $this->checkout_fields = apply_filters('woocommerce_checkout_fields', $this->checkout_fields);

    I know the other part goes in functions but don't know where to place the filter?

    Any help would be much appreciated, I have been at this for hours!

  5. sparklyscotty
    Member
    Posted 1 year ago #

    I am also trying to add/delete fields in checkout. Perhaps it is something they can add to the dashboard in future?

  6. trongtien88
    Member
    Posted 1 year ago #

    Hi Murray,

    Honestly, I don't know much about these coding stuff. But I think you don't need to use the code that you posted.

    You can see my example below:

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

    function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_city']);

    return $fields;
    }

    I put the code above into functions.php in oder to remove these fields: address 2, postcode, company last name, city/town on the checkout page. Hope you can do like mine.

  7. Henry
    Member
    Posted 1 year ago #

    Put this into your theme's functions.php

    add_filter( 'woocommerce_billing_fields', 'custom_woocommerce_billing_fields' );
    
    function custom_woocommerce_billing_fields( $fields ) {
    
       $fields['billing_first_name']	= array(
          'label'          => __('Name', 'woothemes'),
          'placeholder'    => __('Name', 'woothemes'),
          'required'       => true,
          'class'          => array('billing-first-name')
       );
    
       $fields['billing_phone']	= array(
          'label'          => __('Phone', 'woothemes'),
          'placeholder'    => __('Phone', 'woothemes'),
          'required'       => false,
          'class'          => array('billing-phone')
       );
    
     return $fields;
    }

    As you can see this allows you to change the billing address fields. My code example above sets the label, placeholder text, required, and class for both the first name and phone fields. You can do the same for:

    billing_first_name, billing_last_name, billing_company, billing_address_1, billing_address_2, billing_city, billing_postcode, billing_country, billing_state, billing_email, billing_phone

    Source: https://gist.github.com/1860056

  8. applausey
    Member
    Posted 1 year ago #

    Is there anyway i can rename the title of 'Billing Address' under the checkout page?

  9. herrin
    Member
    Posted 1 year ago #

    I can't remember where I found this code (it was late) but putting this in your themes functions.php removes all the checkout fields except the email address. Great for digital sales.

    /* Remove Checkout Fields */
    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields( $fields ) {
    unset($fields['billing']['billing_first_name']);
    unset($fields['billing']['billing_last_name']);
    unset($fields['billing']['billing_company']);
    unset($fields['billing']['billing_address_1']);
    unset($fields['billing']['billing_address_2']);
    unset($fields['billing']['billing_city']);
    unset($fields['billing']['billing_postcode']);
    unset($fields['billing']['billing_country']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_phone']);
    unset($fields['order']['order_comments']);
    return $fields;
    }
    /* Remove Checkout Fields */

    To edit Or remove the words "Billing Address' you need to edit the form-billing.php files (it's easy to find) and place it into your theme folder inside folders - woocommerce/checkout/

    In this example I've commented out the word alltogether.

    <h3><?php /* _e('Billing Address', 'woocommerce'); */ ?></h3>

    Hope that helps.

  10. mcintoshjimmy
    Member
    Posted 1 year ago #

    I just tried Herrin's method and haven't seen any results. Looks like something is a foot. The only success I've had was using the below method to make phone number not required, but can't seem to unset the fields as above. Any idas?

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

  11. hsinke
    Member
    Posted 1 year ago #

    function custom_override_checkout_fields( $fields ) {
    unset($fields['billing_state']);
    return $fields;
    }

    does work. But it did break my layout...

  12. c_turnbull
    Member
    Posted 1 year ago #

    To remove the state field from the checkout and "edit my address" pages, you have to remember to remove it not only from the billing address but the shipping address as well.

    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['shipping']['shipping_state']);
      return $fields;
    }
    
    function custom_override_billing_fields( $fields ) {
      unset($fields['billing_state']);
      return $fields;
    }
    
    function custom_override_shipping_fields( $fields ) {
      unset($fields['shipping_state']);
      return $fields;
    }
  13. Perfect Circle
    Member
    Posted 1 year ago #

    Hi Guys. Does anyone know how to completely remove both Billing and Shipping address forms from the checkout. (I don't want to collect any personal details on my site. I'm only using paypal and can collect shipping details there).

  14. wabcomin
    Member
    Posted 1 year ago #

    My question is the same as perfect circle!!! help anyone out there!

  15. Diane Bourque
    Member
    Posted 1 year ago #

    My question is the same as Perfect Circle and wabcomin - how do we remove both Billing and Shipping addresses from the checkout? I only want people to put in their e-mail and complete the purchase.

  16. Diane Bourque
    Member
    Posted 1 year ago #

    I've just watched this tutorial which worked perfectly for me:
    http://www.youtube.com/watch?v=Dki59cbppTw

  17. hellysium
    Member
    Posted 1 year ago #

    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;
    }
  18. Rolf Hassel
    Member
    Posted 1 year ago #

    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

  19. spedney
    Member
    Posted 1 year ago #

    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!

  20. anandavidyasagars
    Member
    Posted 1 year ago #

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

  21. NKJWP
    Member
    Posted 1 year ago #

    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.

  22. ivan
    Member
    Posted 1 year ago #

    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

  23. spybubblegum
    Member
    Posted 1 year ago #

    @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;
    }
  24. spybubblegum
    Member
    Posted 1 year ago #

    Screenshot of the example above

  25. Solah
    Member
    Posted 11 months ago #

    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 ?

  26. Solah
    Member
    Posted 11 months ago #

    Sorry this is the correct screenshot link:
    click here

  27. Solven
    Member
    Posted 10 months ago #

    samwan Great! Works, Thanks!

  28. roothost
    Member
    Posted 10 months ago #

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

  29. nickrutland
    Member
    Posted 10 months ago #

    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... http://www.w-i-p.net/aidkits/

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

    Thanks in advance WP people :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.