From eedcdd97ba37be0997a20c5ce5f35204253c4ca1 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 27 Apr 2017 14:35:33 +0100 Subject: [PATCH] Compare with timestamp and remove start date once passed for sale products Fixes #14753 --- includes/abstracts/abstract-wc-product.php | 4 ++-- includes/wc-product-functions.php | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php index 5aa23e69be9..0a40c8727ba 100644 --- a/includes/abstracts/abstract-wc-product.php +++ b/includes/abstracts/abstract-wc-product.php @@ -1413,11 +1413,11 @@ class WC_Product extends WC_Abstract_Legacy_Product { if ( '' !== (string) $this->get_sale_price( $context ) && $this->get_regular_price( $context ) > $this->get_sale_price( $context ) ) { $on_sale = true; - if ( $this->get_date_on_sale_from( $context ) && $this->get_date_on_sale_from( $context )->getTimestamp() > time() ) { + if ( $this->get_date_on_sale_from( $context ) && $this->get_date_on_sale_from( $context )->getTimestamp() > current_time( 'timestamp', true ) ) { $on_sale = false; } - if ( $this->get_date_on_sale_to( $context ) && $this->get_date_on_sale_to( $context )->getTimestamp() < time() ) { + if ( $this->get_date_on_sale_to( $context ) && $this->get_date_on_sale_to( $context )->getTimestamp() < current_time( 'timestamp', true ) ) { $on_sale = false; } } else { diff --git a/includes/wc-product-functions.php b/includes/wc-product-functions.php index bdc36fd35ca..cc80ebc06c9 100644 --- a/includes/wc-product-functions.php +++ b/includes/wc-product-functions.php @@ -420,6 +420,7 @@ function wc_scheduled_sales() { if ( $sale_price ) { $product->set_price( $sale_price ); + $product->set_date_on_sale_from( '' ); } else { $product->set_date_on_sale_to( '' ); $product->set_date_on_sale_from( '' );