Adding a new field to checkout and Order info on WooCommerce Admin
Working on my latest project I’ve needed to add a new field to WooCommerce checkout, a “NIF” (Portuguese equivalent of VAT number) field, that isn’t available by default in WooCommerce checkout.
After checking a couple of websites I’ve ended up creating the following snippet:
// Hook in WooCommerce checkout fields and add new field add_filter( 'woocommerce_checkout_fields' , 'add_field_to_checkout' ); // Our hooked in function - $fields is passed via the filter! function add_field_to_checkout( $fields ) { $fields['billing']['billing_fieldname'] = array( 'label' => __('Field Name', 'woocommerce'), 'placeholder' => _x('Field Label as placeholder', 'placeholder', 'woocommerce'), 'required' => false, 'class' => array('form-row-wide'), 'clear' => true ); return $fields; } //Add info on Admin function add_field_to_admin($order){ echo "<p><strong>Field Name:</strong> " . $order->order_custom_fields['_billing_fieldname'][0] . "</p>"; } add_action( 'woocommerce_admin_order_data_after_billing_address', 'add_field_to_admin', 10, 1 );
With this little snippet you can add your new field to “billing” or “shipping” information.
Comments
2 responses to “WooCommerce – Customizing Checkout Fields”
It’s possible put a input upload field in order? I want to upload a file for an order.
I’m also interested…