From c95551c0292163d7a41289592e65d05878af6441 Mon Sep 17 00:00:00 2001 From: mattallan Date: Fri, 22 Sep 2023 12:29:12 +1000 Subject: [PATCH 1/3] With HPOS enabled, when creating a subscription make sure the start date is defaulted correctly --- .../class-wcs-orders-table-subscription-data-store.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/data-stores/class-wcs-orders-table-subscription-data-store.php b/includes/data-stores/class-wcs-orders-table-subscription-data-store.php index c66aa4aff..666ed7c34 100644 --- a/includes/data-stores/class-wcs-orders-table-subscription-data-store.php +++ b/includes/data-stores/class-wcs-orders-table-subscription-data-store.php @@ -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; @@ -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' ); } From 59983198b646ed813310e695a3daf24a07749ea3 Mon Sep 17 00:00:00 2001 From: James Allan Date: Fri, 29 Sep 2023 12:29:21 +1000 Subject: [PATCH 2/3] Default the subscription's start date when saving a subscription meta data Prior to this change there were discrepancies between saving and reading that caused issues when hpos and syncing is enabled. --- .../data-stores/class-wcs-subscription-data-store-cpt.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/data-stores/class-wcs-subscription-data-store-cpt.php b/includes/data-stores/class-wcs-subscription-data-store-cpt.php index d29658b67..ffa8414d3 100644 --- a/includes/data-stores/class-wcs-subscription-data-store-cpt.php +++ b/includes/data-stores/class-wcs-subscription-data-store-cpt.php @@ -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'; From d35affe7f29618ae17dce2328fa01d8a84997c62 Mon Sep 17 00:00:00 2001 From: mattallan Date: Tue, 3 Oct 2023 14:43:34 +1000 Subject: [PATCH 3/3] Add changelog entry --- changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.txt b/changelog.txt index 3286b754c..f8ff649a0 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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.