My website’s woocommerce plugin has a problem. The ‘Order Note’ didn’t understand line break!
For example, if I write this text in ‘Order Note’ section:
1
2
3
It will show like this:
123
And I have to use <br />
between each line!
CodePudding user response:
First you check how is this note stored in the database. WooComerce order notes are stored in the wp_comments table. Check the stored message using phpmyadmin or other database tool.
SELECT *
FROM `wp_comments`
WHERE `comment_post_ID` = {order_id}
ORDER BY `comment_ID` DESC
LIMIT 10
There are 2 options when you add the note with content:
1
2
3
#1 The content of the order note in the database will be the same
1
2
3
This means something is messing up your output.
Order notes are printed using this line:
<?php echo wpautop( wptexturize( wp_kses_post( $note->content ) ) ); // @codingStandardsIgnoreLine ?>
This line will replace newlines with <br>
automatically. So if your comment look ok in the database, look for a problem with the output, check all these functions, hooks they trigger...
#2 The content in the wp_comments will look like
1 2 3
or
123
This means something is messing up your note before storing in the database.
Order note is stored using function $order->add_order_note()
. Inside this function, there is a filter woocommerce_new_order_note_data
that could be doing something with the order note text before saving. Also, when adding order notes manually on the order page, the text is cleaned up using this line
$note = wp_kses_post( trim( wp_unslash( $_POST['note'] ) ) );
I would say the option #2 is more likely, something is messing up the note before the storing but you have to check that.