Automattic / woocommerce-subscriptions-core

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

[HPOS] Update the subscription address when a customer changes their address while paying for a renewal order #413

Closed mattallan closed 1 year ago

mattallan commented 1 year ago

Fixes #412

Description

With HPOS enabled, when a customer is paying for a renewal order and updates their address on the checkout, the subscription doesn't get updated with the newest address.

This is because we were using a legacy order function $subscription->set_address() which calls both update_post_meta() and the CRUD method to set the address prop, but we were never saving the subscription.

There are two issues with our code using set_address():

  1. This function always calls update_post_meta() which shouldn't be used in an HPOS environment. When HPOS is enabled and data syncing disabled, the address was always being saved to the shop_order_placehold post object.
  2. Address data wasn't being saved on the subscription because we weren't calling $subscription->save()

This PR address both of these issues by refactoring how we were using $subscription->set_address().

How to test this PR

Testing these changes requires testing both the Checkout Block and old checkout flows and with HPOS enabled and disabled.

  1. Purchase a subscription
  2. On the Edit Subscription page use the action list to Create pending renewal order
  3. Go to My Account > View Subscription and click to pay for the pending order
  4. While on the checkout, change your address and submit the checkout
  5. Check that the address on the subscription has been updated
  6. When HPOS is enabled with syncing off, confirm the address data is no longer being saved in postmeta.
  7. Perform the same checks for HPOS disabled/enabled and with Checkout Blocks.

Product impact

mattallan commented 1 year ago

Thanks @Jinksi, I've removed those unused variables in b39bf6e. Merging this :shipit: