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():
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.
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().
Inside maybe_update_subscription_address_data() we were already setting up arrays of shipping and billing data so I changed this function to use the set_shipping|billing_$field() functions and then call $subscription->save().
Inside maybe_update_subscription_address_data_from_store_api() we are already given the arrays of address data so I opted to use the new WC Core functions introduced in WC 7.1 which accepts an address array and sets the data
How to test this PR
Testing these changes requires testing both the Checkout Block and old checkout flows and with HPOS enabled and disabled.
Purchase a subscription
On the Edit Subscription page use the action list to Create pending renewal order
Go to My Account > View Subscription and click to pay for the pending order
While on the checkout, change your address and submit the checkout
Check that the address on the subscription has been updated
When HPOS is enabled with syncing off, confirm the address data is no longer being saved in postmeta.
Perform the same checks for HPOS disabled/enabled and with Checkout Blocks.
Product impact
[x] Added changelog entry (or does not apply)
[x] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[x] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
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 bothupdate_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()
: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 theshop_order_placehold
post object.$subscription->save()
This PR address both of these issues by refactoring how we were using
$subscription->set_address()
.maybe_update_subscription_address_data()
we were already setting up arrays of shipping and billing data so I changed this function to use theset_shipping|billing_$field()
functions and then call$subscription->save()
.maybe_update_subscription_address_data_from_store_api()
we are already given the arrays of address data so I opted to use the new WC Core functions introduced in WC 7.1 which accepts an address array and sets the dataHow to test this PR
Testing these changes requires testing both the Checkout Block and old checkout flows and with HPOS enabled and disabled.
Product impact