Last active
December 1, 2016 13:29
-
-
Save mijimoco/b44ee3b39e33956e707e2281d730689c to your computer and use it in GitHub Desktop.
Woocommerce add a custom field to checkout form (ex: tax number 統一編號 in Chinese)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add new field to Checkout | |
*/ | |
// Hook in | |
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields_add_tongbian' ); | |
// Our hooked in function - $fields is passed via the filter! | |
function custom_override_checkout_fields_add_tongbian( $fields ) { | |
$fields['billing']['billing_tongbian'] = array( | |
'label' => __('統一編號', 'woocommerce'), | |
'placeholder' => __('輸入統一編號', 'placeholder', 'woocommerce'), | |
'required' => false, | |
'class' => array('form-row-wide'), | |
'clear' => true | |
); | |
return $fields; | |
} | |
//Edit on Dashboard edit order page | |
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 ); | |
function my_custom_checkout_field_display_admin_order_meta($order){ | |
echo '<p><strong>'.__('統一編號').':</strong> ' . get_post_meta( $order->id, '_billing_tongbian', true ) . '</p>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment