Merge pull request #8391 from justinshreve/sale-date-8357

Make sure sale prices are properly applied when no from date is set and today is used as default (#8357)
This commit is contained in:
Mike Jolley 2015-06-17 13:49:53 +01:00
commit d939d7b395
2 changed files with 6 additions and 4 deletions

View File

@ -1109,7 +1109,8 @@ class WC_Meta_Box_Product_Data {
}
if ( $date_to && ! $date_from ) {
update_post_meta( $post_id, '_sale_price_dates_from', strtotime( 'NOW', current_time( 'timestamp' ) ) );
$date_from = date( 'Y-m-d' );
update_post_meta( $post_id, '_sale_price_dates_from', strtotime( $date_from ) );
}
// Update price if on sale
@ -1119,7 +1120,7 @@ class WC_Meta_Box_Product_Data {
update_post_meta( $post_id, '_price', ( $_POST['_regular_price'] === '' ) ? '' : wc_format_decimal( $_POST['_regular_price'] ) );
}
if ( '' !== $_POST['_sale_price'] && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
if ( '' !== $_POST['_sale_price'] && $date_from && strtotime( $date_from ) <= strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $post_id, '_price', wc_format_decimal( $_POST['_sale_price'] ) );
}

View File

@ -970,7 +970,8 @@ class WC_API_Products extends WC_API_Resource {
}
if ( $date_to && ! $date_from ) {
update_post_meta( $product_id, '_sale_price_dates_from', strtotime( 'NOW', current_time( 'timestamp' ) ) );
$date_from = strtotime( 'NOW', current_time( 'timestamp' ) );
update_post_meta( $product_id, '_sale_price_dates_from', $date_from );
}
// Update price if on sale
@ -980,7 +981,7 @@ class WC_API_Products extends WC_API_Resource {
update_post_meta( $product_id, '_price', $regular_price );
}
if ( '' !== $sale_price && $date_from && $date_from < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
if ( '' !== $sale_price && $date_from && $date_from <= strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $sale_price ) );
}