Created
April 21, 2021 14:10
-
-
Save Spirecool/663cb1ae9a2b3c9a106288be2c6d64bf 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 | |
| // 1. Hide default notes | |
| add_filter( 'woocommerce_enable_order_notes_field', '__return_false' ); | |
| // 2. Create new billing field | |
| add_filter( 'woocommerce_checkout_fields' , 'bbloomer_custom_order_notes' ); | |
| function bbloomer_custom_order_notes( $fields ) { | |
| $fields['billing']['new_order_notes'] = array( | |
| 'type' => 'textarea', | |
| 'label' => 'New Order Notes', | |
| 'class' => array('form-row-wide'), | |
| 'clear' => true, | |
| 'priority' => 999, | |
| ); | |
| return $fields; | |
| } | |
| // 3. Save to existing order notes | |
| add_action( 'woocommerce_checkout_update_order_meta', 'bbloomer_custom_field_value_to_order_notes', 10, 2 ); | |
| function bbloomer_custom_field_value_to_order_notes( $order_id, $data ) { | |
| if ( ! is_object( $order_id ) ) { | |
| $order = wc_get_order( $order_id ); | |
| } | |
| $order->set_customer_note( isset( $data['new_order_notes'] ) ? $data['new_order_notes'] : '' ); | |
| wc_create_order_note( $order_id, $data['new_order_notes'], true, true ); | |
| $order->save(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment