Last active
February 28, 2020 13:36
-
-
Save wickywills/d8ebc0e6d121b6c44ae3c15cef08a759 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
```php | |
/** | |
* Add form fields to Checkout | |
*/ | |
add_filter('woocommerce_checkout_fields', 'wmco_woocommerce_checkout_fields'); | |
function wmco_woocommerce_checkout_fields($fields){ | |
$new_field['billing_org'] = [ | |
'label' => __('Org no.', 'woocommerce'), | |
'placeholder' => _x('Org no.', 'placeholder', 'woocommerce'), | |
'required' => false, | |
'class' => array('form-row-wide'), | |
'clear' => true | |
]; | |
array_splice( $fields['billing'], 4, 0, $new_field ); | |
return $fields; | |
} | |
/** | |
* Display field value on the order edit page | |
*/ | |
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'wmco_woocommerce_checkout_fields_order_edit', 10, 1 ); | |
function wmco_woocommerce_checkout_fields_order_edit($order){ | |
echo '<p><strong>'.__('Org no.').':</strong> ' . get_post_meta( $order->get_id(), '_billing_org_no', true ) . '</p>'; | |
} | |
``` | |
Adjust the value 4 in `array_splice()` to set the order of the new field. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment