diff --git a/includes/data-stores/abstract-wc-order-data-store-cpt.php b/includes/data-stores/abstract-wc-order-data-store-cpt.php index fe8233e8bcf..4081bbe9e2f 100644 --- a/includes/data-stores/abstract-wc-order-data-store-cpt.php +++ b/includes/data-stores/abstract-wc-order-data-store-cpt.php @@ -108,8 +108,8 @@ abstract class Abstract_WC_Order_Data_Store_CPT extends WC_Data_Store_WP impleme $order->set_props( array( 'parent_id' => $post_object->post_parent, - 'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, - 'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, + 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ), + 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ), 'status' => $post_object->post_status, ) ); diff --git a/includes/data-stores/class-wc-coupon-data-store-cpt.php b/includes/data-stores/class-wc-coupon-data-store-cpt.php index da05e16f2a2..8f9b7310144 100644 --- a/includes/data-stores/class-wc-coupon-data-store-cpt.php +++ b/includes/data-stores/class-wc-coupon-data-store-cpt.php @@ -123,8 +123,8 @@ class WC_Coupon_Data_Store_CPT extends WC_Data_Store_WP implements WC_Coupon_Dat array( 'code' => $post_object->post_title, 'description' => $post_object->post_excerpt, - 'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, - 'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, + 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ), + 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ), 'date_expires' => metadata_exists( 'post', $coupon_id, 'date_expires' ) ? get_post_meta( $coupon_id, 'date_expires', true ) : get_post_meta( $coupon_id, 'expiry_date', true ), // @todo: Migrate expiry_date meta to date_expires in upgrade routine. 'discount_type' => get_post_meta( $coupon_id, 'discount_type', true ), 'amount' => get_post_meta( $coupon_id, 'coupon_amount', true ), diff --git a/includes/data-stores/class-wc-data-store-wp.php b/includes/data-stores/class-wc-data-store-wp.php index 10222a73a27..ef738f4ac39 100644 --- a/includes/data-stores/class-wc-data-store-wp.php +++ b/includes/data-stores/class-wc-data-store-wp.php @@ -630,4 +630,16 @@ class WC_Data_Store_WP { ); wp_cache_delete( 'lookup_table', 'object_' . $id ); } + + /** + * Converts a WP post date string into a timestamp. + * + * @since 4.7.0 + * + * @param string $time_string The WP post date string. + * @return int|null The date string converted to a timestamp or null. + */ + protected function string_to_timestamp( $time_string ) { + return '0000-00-00 00:00:00' !== $time_string ? wc_string_to_timestamp( $time_string ) : null; + } } diff --git a/includes/data-stores/class-wc-product-data-store-cpt.php b/includes/data-stores/class-wc-product-data-store-cpt.php index c0e348a1da1..9e5690853b7 100644 --- a/includes/data-stores/class-wc-product-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-data-store-cpt.php @@ -170,8 +170,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da array( 'name' => $post_object->post_title, 'slug' => $post_object->post_name, - 'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, - 'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, + 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ), + 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ), 'status' => $post_object->post_status, 'description' => $post_object->post_content, 'short_description' => $post_object->post_excerpt, diff --git a/includes/data-stores/class-wc-product-variation-data-store-cpt.php b/includes/data-stores/class-wc-product-variation-data-store-cpt.php index 5dd45b04536..534ba382ef8 100644 --- a/includes/data-stores/class-wc-product-variation-data-store-cpt.php +++ b/includes/data-stores/class-wc-product-variation-data-store-cpt.php @@ -62,8 +62,8 @@ class WC_Product_Variation_Data_Store_CPT extends WC_Product_Data_Store_CPT impl array( 'name' => $post_object->post_title, 'slug' => $post_object->post_name, - 'date_created' => 0 < $post_object->post_date_gmt ? wc_string_to_timestamp( $post_object->post_date_gmt ) : null, - 'date_modified' => 0 < $post_object->post_modified_gmt ? wc_string_to_timestamp( $post_object->post_modified_gmt ) : null, + 'date_created' => $this->string_to_timestamp( $post_object->post_date_gmt ), + 'date_modified' => $this->string_to_timestamp( $post_object->post_modified_gmt ), 'status' => $post_object->post_status, 'menu_order' => $post_object->menu_order, 'reviews_allowed' => 'open' === $post_object->comment_status,