Add extra field to check-out
/**
* Add an extra field in checkout (VAT)
*/
function twstudio_custom_override_checkout_fields( $fields ) {
$fields['billing']['billing_vat'] = array(
'label' => __('VAT', 'woocommerce'),
'placeholder' => _x('', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields' , 'twstudio_custom_override_checkout_fields' );
// Display field value (VAT) on the order edit page
function custom_checkout_field_display_admin_order_meta($order){
echo '<p><strong>'.__('VAT').':</strong> ' . get_post_meta( $order->get_id(), '_billing_vat', true ) . '</p>';
}
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'custom_checkout_field_display_admin_order_meta', 10, 1 );