• Resolved murilocarvalho

    (@murilocarvalho)


    I’m trying to remove address 2 everywhere (Checkout, My Account > Addresses) and reorder some others following the documentation from https://woocommerce.com/document/tutorial-customising-checkout-fields-using-actions- and-filters/ and other forums on the internet.

    The field is removed, but I noticed an error. When I add a product and go to the cart page to simulate shipping, the address is shown correctly, but when I go to the checkout page and return to the cart page, the undefined value is added to the address. This only happens because of the removal of address 2.

    I’ve already tried using the woocommerce_default_address_fields, woocommerce_billing_fields, woocommerce_shipping_fields and woocommerce_checkout_fields filters. I’ve also disabled plugins that may be related to WooCommerce.

    This is the most recent code from my attempts:

    add_filter( 'woocommerce_billing_fields' , 'custom_billing_fields' );
      function custom_billing_fields( $fields ) {
    
        unset($fields ['billing_company']);
    
        $fields['billing_neighborhood']['label'] = 'Bairro';
    
        $fields['billing_number']['class'] = array( 'form-row-first', 'address-field' );
        $fields['billing_phone']['class'] = array( 'form-row-first', 'address-field' );
        $fields['billing_cpf']['class'] = array( 'form-row-last', 'person-type-field', 'validate-required' );
        $fields['billing_neighborhood']['class'] = array( 'form-row-first', 'address-field' );
    
        $fields['billing_email']['priority'] = 21;
        $fields['billing_phone']['priority'] = 22;
        $fields['billing_number']['priority'] = 60;
        $fields['billing_neighborhood']['priority'] = 75;
    
        $fields['billing_neighborhood']['required'] = true;
    
          return $fields;
      }
    
      add_filter( 'woocommerce_shipping_fields' , 'custom_shipping_fields' );
      function custom_shipping_fields( $fields ) {
    
        unset($fields ['shipping_company']);
    
        $fields['shipping_neighborhood']['label'] = 'Bairro';
    
    
        $fields['shipping_number']['class'] = array( 'form-row-first', 'address-field' );
        $fields['shipping_neighborhood']['class'] = array( 'form-row-first', 'address-field' );
    
    
        $fields['shipping_number']['priority'] = 60;
        $fields['shipping_neighborhood']['priority'] = 75;
    
    
        $fields['shipping_neighborhood']['required'] = true;
    
        return $fields;
      }
    
      add_filter( 'woocommerce_default_address_fields', 'custom_default_address_fields' );
      function custom_default_address_fields( $fields ) {
    
        unset($fields['address_2']);
        
        if(is_account_page() || is_checkout()) {
          $fields['postcode']['class'] = array( 'form-row-first', 'address-field' );
          $fields['address_1']['class'] = array( 'form-row-last', 'address-field' );
          $fields['city']['class'] = array( 'form-row-last', 'address-field' );
          $fields['state']['class'] = array( 'form-row-last', 'address-field' );
        }
    
        return $fields;
      }

    I’ve tried using $unset($fields[‘billing_address_2’]); in the ‘woocommerce_billing_fields’ filter, $unset($fields[‘shipping_address_2’]); in the filter ‘woocommerce_shipping_fields’ and $unset($fields[‘billing’][‘billing_address_2’]); $unset($fields[‘shipping’][‘shipping_address_2’]); in the ‘woocommerce_checkout_fields’ filter.

    None of the attempts worked. Every time I recalculate in the cart, the address appears correctly (but I noticed that it only asks/shows the city). When I go to the checkout page and return to the cart, the street address is also added, but with the undefined that comes from address 2.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter murilocarvalho

    (@murilocarvalho)

    I also just tried to hide it through the Appearance > WooCommerce > Checkout menu, and it’s causing the same problem.

    Thread Starter murilocarvalho

    (@murilocarvalho)

    I just verified that the problem started from version 7.5.0. I tested it on 7.4.1 and it’s normal.

    Same issue, my cart page “Order Summary” displays the shipping section as the following example:
    Shipping to: 1111 test ave, undefined, Tampa, FL 35254

    @murilocarvalho you right, I made a Rollback version to 7.4.1 at it looks fine, example:
    Shipping to: 1111 test ave, Tampa, FL 35254

    Any solution?

    Having the same issues, shows undefined within the cart page. I only have a code disabling company name.

    • This reply was modified 1 year, 11 months ago by bramokki.

    same here, didn’t find a solution. I rolled back to 7.4.1 and still have the same issue

    • This reply was modified 1 year, 11 months ago by ilovebarushka.
    Thread Starter murilocarvalho

    (@murilocarvalho)

    @ilovebarushka When you return to version 7.4.1, try to enable Address 2 again and go to the checkout page, you will see that “undefined” will be written in the field… Delete it, go back to the cart, simulate shipping to the address back to normal and then disable Address 2 again.

    For those who want to use the latest version of WooCommerce, you need to leave Address 2 enabled and hide it with CSS using display:none; !important (needs !important, because for some reason, when we use display:none on the Address 2 field, the field gets an inline-style display: block)

    @murilocarvalho thank you, I did what you suggested and it worked for one “undefined” but there were still two more of “undefined” so I enabled postcode for shipping and shipping 2 and enabled and it worked.

    Thanks!

    Saif

    (@babylon1999)

    Hello @murilocarvalho,

    Thank you for bringing this to our attention.

    I was able to reproduce what you’re describing. A GitHub report was opened here: https://github.com/woocommerce/woocommerce/issues/37627

    Currently, we are unable to provide an estimate for when the team will review or address the issue as bug reports are evaluated based on various criteria. I suggest you subscribe to the thread for further updates.

    CC: @ilovebarushka , @bramokki , @cdatab

    Cheers!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘unset Address 2 Field Return Undefined in Cart Page’ is closed to new replies.