WooCommerce — how to add customer VAT field for billing and admin view order page

Some payment gateway need a customer VAT field to be sent to make the payment.While i was developing pagbrasil gateway for WooCommerce, i found WooCommerce do not support to add extra field for checkout and order.

Of course, for the sake of updating WooCommerce,i can not change the WooCommerce  code directly. WooCommerce was running as a plugin upon WordPress. i just need another wordpress plugin to insert a VAT field.By the way,the payment gateway for WooCommerce was also build as a pluging for wordpress,just one thing differcence,it denpends on the WooCommerce plugin.

To learning how to develop a wordpress plugin,you need to refer to wordpress docs,there are lots tutor online.i am going to the code part of this work¬† — add hook and filter for checkout page and order view page :

[codesyntax lang=”php”]

//add VAT field to checkout page
function VAT_override_checkout_fields( $fields ) {
	$fields['billing']['VAT_code'] = array(
	'label'     => __('VAT', 'woocommerce'),
	'placeholder'   => _x('VAT', 'placeholder', 'woocommerce'),
	'required'  => true,
	'class'     => array('form-row-wide'),
	'clear'     => true

	return $fields;
add_filter( 'woocommerce_checkout_fields' , 'VAT_override_checkout_fields');

function VAT_custom_checkout_field_order_meta_keys( $order ) {
	echo "<span><strong>VAT:</strong>" .
	$order->VAT_code . "</span>";
add_action( 'woocommerce_admin_order_data_after_billing_address', 'VAT_custom_checkout_field_order_meta_keys' );




Leave a Reply

Your email address will not be published. Required fields are marked *