When a WP site has a timezone set in the settings, subscriptions created via the checkout have a date created that is offset by the timezone incorrectly.
This is caused by a bug in the wcs_create_subscription() function where it passes a UTC mysql date string (2023-10-12 14:53:24) to $subscription->set_date_created() but if you look at the description of that function you'll notice that it says that:
If the DateTime string has no timezone or offset, WordPress site timezone will be assumed.
This means that when we pass a mysql date format, it assumes the date is in the site's local time.
This PR fixes it by converting the mysql date into a timestamp which the set_date_created() will assume is in UTC.
How to test this PR
Go to the WordPress admin dashboard.
Go to Settings → General and set the site's timezone (eg UTC+10)
4.Purchase a subscription through the checkout.
Go to the admin |Orders list table.
Edit the newly created order and scroll down to the related orders table.
On develop note the subscription has a created date -10 hours.
On this branch it should be correct.
You can also check the date created in the database and you'll notice that on develop the GMT date is double the expected offset (eg -20 hours).
Product impact
[x] Added changelog entry (or does not apply)
[ ] Will this PR affect WooCommerce Subscriptions? yes/no/tbc, add issue ref
[ ] Will this PR affect WooCommerce Payments? yes/no/tbc, add issue ref
[ ] Added deprecated functions, hooks or classes to the spreadsheet
Description
When a WP site has a timezone set in the settings, subscriptions created via the checkout have a date created that is offset by the timezone incorrectly.
This is caused by a bug in the
wcs_create_subscription()
function where it passes a UTC mysql date string (2023-10-12 14:53:24
) to$subscription->set_date_created()
but if you look at the description of that function you'll notice that it says that:This means that when we pass a mysql date format, it assumes the date is in the site's local time.
This PR fixes it by converting the mysql date into a timestamp which the
set_date_created()
will assume is in UTC.How to test this PR
4.Purchase a subscription through the checkout.
develop
note the subscription has a created date -10 hours.You can also check the date created in the database and you'll notice that on
develop
the GMT date is double the expected offset (eg -20 hours).Product impact