Customers can be of two types either standard or business one. Standard customer selling process run smoothly using WooCommerce standard features but if the customer is of business type then Seller has to take their GST/VAT number to generate TAX invoice.
This blog helps you to tackle the problem of entering GST/VAT number on checkout page for business customer without plugin. There are many plugins which can do it but we strongly recommend using hooks code instead of plugin (Well there are many reasons for it). If you want to know how to ADD GST BILLING on your WooCommerce store then click here
This task contain three parts as below:
- GST/VAT number box in WooCommerce Checkout page
- Showing GST/VAT number in WooCommerce Admin on order page
- Showing GST/VAT number in WooCommerce processing emails
So lets do the above point one by one.
GST/VAT number box in WooCommerce Checkout page
Add the below code on your functions.php file of child theme.
add_action( 'woocommerce_after_order_notes', 'wc_vat_field' );
/**
* GST/VAT Number in WooCommerce Checkout
*/
function wc_vat_field( $checkout ) {
echo '<div id="wc_vat_field"><h2>' . __('GST/VAT Number') . '</h2>';
woocommerce_form_field( 'vat_number', array(
'type' => 'text',
'class' => array( 'vat-number-field form-row-wide') ,
'label' => __( 'GST/VAT Number' ),
'placeholder' => __( 'Enter your GST/VAT number' ),
), $checkout->get_value( 'vat_number' ));
echo '</div>';
}
Once you added the above code, add the below code just after the above code. We are doing this to save the GST/VAT number which customer added in box.
add_action( 'woocommerce_checkout_update_order_meta', 'wc_checkout_vat_number_update_order_meta' );
/**
* Save GST/VAT Number in the order meta
*/
function wc_checkout_vat_number_update_order_meta( $order_id ) {
if ( ! empty( $_POST['vat_number'] ) ) {
update_post_meta( $order_id, '_vat_number', sanitize_text_field( $_POST['vat_number'] ) );
}
}
Showing GST/VAT number in WooCommerce Admin on order page
Once above task done, now time to show the GST/VAT number to Admin on order detail page by adding the following code in same functions.php file after above codes.
add_action( 'woocommerce_admin_order_data_after_billing_address', 'wc_vat_number_display_admin_order_meta', 10, 1 );
/**
* Display GST/VAT Number in order edit screen
*/
function wc_vat_number_display_admin_order_meta( $order ) {
echo '<p><strong>' . __( 'GST/VAT Number', 'woocommerce' ) . ':</strong> ' . get_post_meta( $order->id, '_vat_number', true ) . '</p>';
}
Showing GST/VAT number in WooCommerce processing emails
Once above task complete, its very important to show the GST/VAT number which customer provided on checkout page. So we gonna add one more below code to achieve the same in same functions.php file.
add_filter( 'woocommerce_email_order_meta_keys', 'wc_vat_number_display_email' );
/**
* GST/VAT Number in emails
*/
function wc_vat_number_display_email( $keys ) {
$keys['VAT Number'] = '_vat_number';
return $keys;
}
Once you added the above code, GST/VAT number will also show on emails of WooCommerce.
So that’s all you need to do to get the GST/VAT number from business customer and display them in order and emails.
Happy coding!
[caldera_form id=”CF60ca2e3ccf64f”]