WordPress.org

Support

Support » Plugins and Hacks » [WooCommerce] Remove fields on Edit Address

[WooCommerce] Remove fields on Edit Address

  • trongtien88
    Member

    @trongtien88

    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.

Viewing 15 replies - 1 through 15 (of 28 total)
  • 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

    trongtien88
    Member

    @trongtien88

    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?

    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!

    sparklyscotty
    Member

    @sparklyscotty

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

    trongtien88
    Member

    @trongtien88

    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.

    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

    applausey
    Member

    @applausey

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

    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.

    mcintoshjimmy
    Member

    @mcintoshjimmy

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

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

    does work. But it did break my layout…

    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;
    }
    Perfect Circle
    Member

    @perfect-circle

    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).

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

    Diane Bourque
    Member

    @dianebourque

    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.

    Diane Bourque
    Member

    @dianebourque

    I’ve just watched this tutorial which worked perfectly for me:

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