|

Plugin to Add Custom Tax/VAT Field On WooCommerce Checkout

woocommerce VAT cF

A while back I did a shop on WooCommerce and I needed to add the tax id on the checkout page and also to be displayed on the order page or in the email. There are a few tutorials over the internet that can help you with this even a paid plugin if you want validation and more advanced configuration features. The below tutorials have been used to build a plugin that is inserting a Vat field in the checkout page of WooComerce and also is displaying it in the order page:

Because there is the risk that the code to be deleted if I implement it directly in the WooCommerce I preferred to create a plugin. In this way I avoid losing the field when the plugin is created. Creating the plugin is not to hard and it is also clean. Below is the code that I have used to add the field in the checkout:

add_filter( 'woocommerce_checkout_fields' , array( $this,'VAT_override_checkout_fields' ));

	public function VAT_override_checkout_fields( $fields ) {
				$fields['billing']['VAT_cui'] = array(
				'label'     => __('VAT', 'woocommerce'),
				'placeholder'   => _x('VAT', 'placeholder', 'woocommerce'),
				'required'  => true,
				'class'     => array('form-row-wide'),
				'clear'     => true
				);

				return $fields;
}

Below is the code to add the code in the order page:

add_action( 'woocommerce_admin_order_data_after_billing_address',  array( $this,'VAT_custom_checkout_field_order_meta_keys' );
	public function VAT_custom_checkout_field_order_meta_keys( $order ) {
		echo "<p><strong>VAT:</strong>" .
		$order->order_custom_fields['_VAT_cui'][0] . "</p>";

}

The script and plugin don’t update the user meta it is only inserting the VAT in the order. Every time a new command will be made the file will be there together with the VAT and if the customer would want to change it can be changed.

Below is the plugin that can be used to add the VAT mandatory custom field in the checkout page of Woocommerce, it can be installed like any other plugin but to work be sure that WooCommerce plugin is installed.

To download it just the article with one of the below links.

[sociallocker]

Do you need help with your projects?

If you need help with your projects, don’t wait any longer. Get in touch with us today and we’ll be happy to help you out.

DOWNLOAD

[/sociallocker]

== Installation ==

1. Upload the entire ‘woocommerce-VAT’ folder to the ‘/wp-content/plugins/’ directory
2. Activate the plugin through the ‘Plugins’ menu in WordPress

== Changelog ==

= 1.0.0 =
* Initial Release

Similar Posts