Skip to content

Conversation

@barryhughes
Copy link
Member

@barryhughes barryhughes commented Aug 25, 2022

Adds support for Customer Notes to Custom Order Tables.

As a quick reminder, from a UI perspective, customer notes surface both in the order editor and the checkout page, as in the following screenshot:

Editor screen Checkout page
Editor screen, showing the Customer Note field Checkout page, showing the Customer Note field

Traditionally/under the CPT data-store, these notes have been stored in the post_excerpt field of the wp_posts table.

Closes #34148.

How to test the changes in this Pull Request:

Start by testing migrations.

  1. Disable the COT feature (via WooCommerce ‣ Settings ‣ Advanced ‣ Custom Data Stores) and delete your Custom Order Tables (via WooCommerce ‣ Status ‣ Tools).
  2. Create some test orders, and set customer notes for some of them.
  3. Re-enable the COT feature (but leave the posts table authoritative for the time being), re-generate the tables, and run the migration (wp wc cot migrate).
  4. Once the migration completes, inspect the wp_wc_orders table. You should see a customer_note column and the value of this column should match what you see in the post_excerpt column for the corresponding rows from the wp_posts table:

query-customer-notes-excerpts

Ensure we can still edit customer notes.

  1. At this stage, the posts table should still be authoritative. Also check that Keep the posts table and the orders tables synchronized is enabled (both these things are managed via WooCommerce ‣ Settings ‣ Advanced ‣ Custom Data Stores).
  2. Edit one of the orders then edit the customer note. Save/update.
  3. The change should have persisted.
  4. Now change the authoritative tables to COT and repeat the test (since a change was made to the meta box templates—which are shared by both the CPT and COT editors—I want to check editor-based updates of this field work for COT as well as CPT).

Now test the COT data-store as a customer.

  1. With COT enabled (again: COT tables should be authoritative, synchronization with posts should be enabled) visit the storefront and place an order.
  2. On the checkout screen, specify a Customer Note. Place the order.
  3. As site administrator, edit the order and make sure you can see the Customer Note.
  4. Using a DB tool of your choosing, ensure the matching row in wp_posts has the same Customer Note (but, stored in the post_excerpt field).

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Aug 25, 2022
@barryhughes barryhughes requested review from a team and jorgeatorres and removed request for a team August 25, 2022 22:43
Copy link
Member

@jorgeatorres jorgeatorres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @barryhughes! Top-notch work as usual 🥇.

@jorgeatorres jorgeatorres merged commit 93a82c3 into trunk Sep 8, 2022
@jorgeatorres jorgeatorres deleted the fix/34148-cot-order-notes branch September 8, 2022 12:39
@github-actions github-actions bot added this to the 7.0.0 milestone Sep 8, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Sep 8, 2022

Hi @jorgeatorres, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:

  • Add the release: add testing instructions label

@bobteree
Copy link

Hello,
I believe there is a bug in release 7.0.0. The "customer provided note" can be edited by the customer or backend store-owner. When you test this from the backend, NO formatting is saved. You can test this by creating a new order or editing this value in an existing order. Try cutting and pasting the following text into the "Customer provided notes" field:

I love WooCommerce 123.

It really is great!

Thanks!

When I input text with carriage returns (or hard line breaks), they all dissappear and the string is simply saved as:

I love WooCommerce 123. It really is great! Thanks!

All line breaks dissapear.

We use this feature a lot on the backend and this has worked for years. We need it to support line-breaks.

THANKS!

@bobteree
Copy link

WooCommerce support opened this ticket: ticket ID: 5640654-zen

@barryhughes
Copy link
Member Author

Thanks for the note: we'll progress this via #35112.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[COT] order note not saved

4 participants