woocommerce

Woocommerce Address1 and Address2 display on one line


I've searched for hours, tested a lot of things (editing files with no visible result), but i can't seem to find the solution so i humbly present my case for this community :-)

I'm using Woocommerce and set the address2 field required and renamed it so i can use it as a field for the house number. So far so good.

The problem i have is i want to display this on 1 line and not on 2 lines like the image below. This is the case on several pages, but mainly the one in the example is the most important one. Does anyone have any clue in what .php file or template this is hidden?

Thanks so much!

Example


Solution

  • You can use the woocommerce_order_formatted_billing_address filter hook that allows you to change the billing address format. try the below code.

    function change_order_formatted_billing_address( $address, $WC_Order ) {
        
        $current_screen = get_current_screen();
    
        if( $current_screen == 'shop_order' && isset( $_GET['action'] ) && $_GET['action'] == 'edit' ){
    
            $address = array(
                'first_name'    => $WC_Order->billing_first_name,
                'last_name'     => $WC_Order->billing_last_name,
                'vat'           => $WC_Order->billing_vat,
                'company'       => $WC_Order->billing_company,
                'address_1'     => $WC_Order->billing_address_1.' '.$WC_Order->billing_address_2,
                'city'          => $WC_Order->billing_city,
                'state'         => $WC_Order->billing_state,
                'postcode'      => $WC_Order->billing_postcode,
                'country'       => $WC_Order->billing_country
            );
         }
        
        return $address;
    
    }
    
    add_filter( 'woocommerce_order_formatted_billing_address' , 'change_order_formatted_billing_address', 10, 2 );
    

    Tested and works

    enter image description here