Automattic / woocommerce-subscriptions-core

Subscriptions core package for WooCommerce
Other
80 stars 29 forks source link

Saving customer note from Edit Subscription page not working when HPOS is enabled #575

Closed mattallan closed 3 months ago

mattallan commented 4 months ago

Fixes 4618-gh-woocommerce/woocommerce-subscriptions

Description

Updating the customer note on the Edit Subscription page doesn't work on stores using HPOS as their datastore:

image

In our WCS_Meta_Box_Subscription_Data::output() function we load in this customer note field with the following code:

<textarea rows="1" cols="40" name="excerpt" tabindex="6" id="excerpt" placeholder="<?php esc_attr_e( 'Customer\'s notes about the order', 'woocommerce-subscriptions' ); ?>"><?php echo wp_kses_post( $subscription->get_customer_note() ); ?></textarea>

On save, in a WP Post environment, the $_POST['excerpt'] data is handled by WordPress core's own save posts process, but in an HPOS environment, we need to manually save this data which is done by this PR.

[!NOTE]
In WooCommerce Core, they've updated this textarea to have name 'customer_note' instead of excerpt. I've opted to leave ours as 'excerpt' for backwards compatibility and I couldn't think of a reason to update it. Keen to hear what others think.

The only reason I would consider changing it is to be consistent with WooCommerce/Orders.

How to test this PR

  1. On trunk, enable HPOS
  2. Purchase a subscription product
  3. Visit the WP Admin > Edit Subscription page
  4. Under the shipping details, click the pencil and edit the customer note field.
  5. Hit Update and on page refresh, notice how the customer note changes aren't sticking
  6. Check out this branch and update the customer note to confirm it's working
  7. Disable HPOS and confirm saving the subscription as a WP Post continues to work.

Product impact

spraveenitpro commented 3 months ago

@mattallan any idea when this will be merged?

mattallan commented 3 months ago

any idea when this will be merged?

@spraveenitpro our next Woo Subscriptions release is scheduled for 28th March so it'll definitely make it into that release. Let me know if there's any issue with that and we can prepare a pre-release if needed.