We already saw how to hide Order Notes on the WooCommerce checkout page. This time around, however, our goal is to “move” them – and specifically remove them from their default position (under the shipping form) and add them back under the billing form.
As you can imagine, this is a combo snippet: (1) we remove them (and we’ll use the snippet as per the link above) and (2) we create a new billing field. Finally, (3) we also need to “save” this new field value into the original order notes custom field meta.
If this is difficult to understand don’t worry – just copy/paste the snippet into your functions.php and see magic happen. Enjoy!
PHP Snippet: Move Order Notes @ WooCommerce Checkout
/**
* @snippet Move Order Notes @ WooCommerce Checkout
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 3.9
* @community https://businessbloomer.com/club/
*/
// 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();
}
Hello, I would like to show the comment field only when a new delivery address is selected. After ticking the box “Ship to another Address”.
Is there a solution for this? Best regards, Fabian
Hi Fabian, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Thank you so much!
It works amazingly…
I did a small change in the last function, I share here:
Otherwise it was saving empty notes with every order!
Cool!
How to place the order notes field under the payment methods?
Hello Joao, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hello, I would like to ask you how I can move order comment to the hook position “woocommerce_review_order_before_submit”. Thank you
Hi German, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Thanks for the snippet, but I think you might be conflating/combining the simple ‘Order comments’ text area on the checkout page (that has the id “order_comments”) with the ‘Order notes’ feature available in the back-end after an order is placed. Part 3 of your snippet doesn’t set the order_comments field but instead tries to create a new order note. I’ve taken a snip here if it helps explain it: https://snipboard.io/O6o5ea.jpg
Thank you so much. If you just remove the “wc_create_order_note” line, does it work?
Very good Rodolfo,
I have verified that now the order notes are not saved in the customer data, they are not added to the order. They only appear in emails, but not in orders.
Regards!
Thank you Tomas! I find it weird it displays in emails and not in the orders, they come from the same data. Can you try with a different theme and no plugins but Woo?
Hi Rodolfo,
thanks for your answer. My theme is Storefront. It appears in the email but I assure you that it does not appear in the order data.
Greetings!
Thank you. I’ve revised the snippet, let me know
Thanks Rodolfo for the inconvenience.
Still not saved in the order data, however, I receive an additional email with the order notes.
If nobody else has that problem, I suppose it will be a theme of my website.
Anyway, thank you very much.
Regards!!
You’re welcome 🙂
As always – works like a charm! But do not forget about placeholder text 🙂
Greetings!
Awesome!
Hi Rodolfo
It is a great idea to move the order notes, so it is much better. But it has two forgotten details:
The first is that there is no placeholder (I have easily solved this).
The second is that by default, in woocommerce when the customer selects the collection locally, the order notes are hidden, so it is in that location. However, with this code they are not hidden.
A greeting!
Thank you!