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]

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

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.

9 thoughts on “Plugin to Add Custom Tax/VAT Field On WooCommerce Checkout”

  1. pretty cool your plugin, thanks a lot.
    unfortunately i get an error in woocommerce -> orders -> orderdetail: Fatal error: Cannot use string offset as an array in /pathtowoocommerce/wp-content/plugins/woocommerce-vat-checkout-add/woocommerce-vat.php on line 66

    Reply
  2. i fixed it:


    public function VAT_custom_checkout_field_order_meta_keys( $order ) {
    $my_order_meta = get_post_custom( $order->id );
    echo "UmsatzsteuerID: ".$my_order_meta['_VAT_cui'][0]."";
    }

    Reply
  3. Hi.
    I put this plugin and activate it.
    In the check out process can write the vat number.
    After, this vat number doesnt appears in orders, emails, etc..

    do you know why?

    Thank you.

    Reply
  4. I noticed that in the last version of woocommerce, this plugin doesn’t work at all. As @sergio pointed, in the order page the VAT doesn’t appear… Is there any compatibility issues? Thanks!

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.