Home > Software engineering >  WooCommerce - Getting VAT in Order Email
WooCommerce - Getting VAT in Order Email

Time:12-07

I am using a snippet to get my clients' VAT details visible on Frontend and Backend and the part below to have it printed in order emails:

// VAT Number in emails
add_filter( 'woocommerce_email_order_meta_keys', 
'supine_vat_number_display_email' );

function supine_vat_number_display_email( $keys ) {
$keys['VAT Number'] = '_billing_vat';
return $keys;
}

It works well but it is outside the Billing Address section where I want it to be.

May anyone help and assist please to update the code above for the VAT to appear in the Billing Address on Order Emails.

Thank you

I tried to update the code but could not make it work properly.

CodePudding user response:

The woocommerce_email_order_meta_keys is deprecated. If you want to add the VAT number to the billing address you could use the woocommerce_order_get_formatted_billing_address filter, like in the example below.

add_filter( 'woocommerce_order_get_formatted_billing_address', function( $address, $raw_address, $order ) {
    if ( ! empty( $vat_number = $order->get_meta( '_billing_vat' ) ) ) {
        $address .= sprintf( '<br>%s: %s', __( 'VAT number', 'woocommerce' ), $vat_number );
    }
    return $address;
}, 10, 3 );

Please note that this will add the VAT number to the billing address everywhere. Not just in the emails. So if you already are using filters to display the VAT number on the front- and backend you might see a duplicate VAT number.

  • Related