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' );




WooCommerce — How to clear cart content after payment

Sometimes you want to clear cart content.For example, if the customer was redirected back to your WooCommerce store after payment,you need to clear WooCommerce shopping cart to avoid dumplicated order.so how?

global $woocommerce; $woocommerce->cart->empty_cart(); 

Keep in mind the $woocommerce is a global variable. you need to explicitly declare before you can call it in function or methods.

To clear cart only for some special page, you can detect page with function is_page()  which you can pass any page title, ID or slug.




PHP — PHP Protocol https not supported or disabled in libcurl

While i was developing WooCommerce payment module for Pagbrasil gateway,i got a curl error msg as:

PHP Protocol https not supported or disabled in libcurl

To check if https protocol was supported by the server,i created a script called a.php and put <?php phpinfo(); ?> in it.From the curl section of the phpinfo page, i found  that https protocol were not listed. so the cURL was not built with SSL support.The only way is to recompile the php.