Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With HPOS + compatibility mode enabled, manually created subscriptions don't have a start date in the new order tables #514

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Fix - When HPOS is enabled, make the orders_by_type_query filter box work in the WooCommerce orders screen.
* Fix - Resolved an issue that caused paying for failed/pending parent orders that include Product Add-ons to not calculate the correct total.
* Add - Introduce the "Subscription Relationship" column under the Orders list admin page when HPOS is enabled.
* Fix - Store the correct subscription start date in postmeta and ordermeta when HPOS and data syncing is being used.

= 6.2.0 - 2023-08-10 =
* Add - Introduce an updated empty state screen for the WooCommerce > Subscriptions list table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ protected function persist_order_to_db( &$subscription, bool $force_all_fields =
];

if ( empty( $existing_meta_data ) ) {
// If we're saving a start date for the first time and it's empty, set it to the created date as a default.
if ( '_schedule_start' === $new_meta_data['key'] && empty( $new_meta_data['value'] ) ) {
$new_meta_data['value'] = $subscription->get_date( 'date_created' );
}

$this->data_store_meta->add_meta( $subscription, (object) $new_meta_data );
} elseif ( $existing_meta_data->meta_value !== $new_meta_data['value'] ) {
$new_meta_data['id'] = $existing_meta_data->meta_id;
Expand Down Expand Up @@ -649,7 +654,7 @@ protected function init_order_record( \WC_Abstract_Order &$subscription, int $su
continue;
}

// If we're setting the start date and it's missing, we set it to the created date.
// If we're reading in the start date and it's missing, set it in memory to the created date.
if ( 'schedule_start' === $prop_key && empty( $meta_data[ $meta_key ] ) ) {
$meta_data[ $meta_key ] = $subscription->get_date( 'date_created' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ protected function update_post_meta( &$subscription ) {
foreach ( $this->get_props_to_update( $subscription, $this->subscription_meta_keys_to_props ) as $meta_key => $prop ) {
$meta_value = ( 'schedule_' == substr( $prop, 0, 9 ) ) ? $subscription->get_date( $prop ) : $subscription->{"get_$prop"}( 'edit' );

if ( 'schedule_start' === $prop && ! $meta_value ) {
$meta_value = $subscription->get_date( 'date_created' );
}

// Store as a string of the boolean for backward compatibility (yep, it's gross)
if ( 'requires_manual_renewal' === $prop ) {
$meta_value = $meta_value ? 'true' : 'false';
Expand Down
Loading