Change format adress WordPress

To change the format of the default woocommerce adresses. Change the following snippet to your own needs. In this example, a custom housenumber field is being added to adress_1.

add_filter( 'woocommerce_order_formatted_billing_address' , 'woo_custom_order_formatted_billing_address', 10, 2 );

function woo_custom_order_formatted_billing_address( $address, $WC_Order ) {

    $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 .' '.get_post_meta($WC_Order->get_id(),'billing_number',true),
        'address_2'     => $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;

}

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest
Author picture

SitiWeb is de expert op het gebied van WordPress. gespecialiseerd in het leveren van maatwerk.

Leave a comment

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *