Fixed format of date after reading from DB

This commit is contained in:
Florian Ludwig 2016-01-08 13:34:19 +01:00
parent 734f3aed18
commit f41a0a539f
2 changed files with 52 additions and 8 deletions

View File

@ -1434,8 +1434,19 @@ class WC_API_Products extends WC_API_Resource {
$sale_price = get_post_meta( $product_id, '_sale_price', true );
}
$date_from = isset( $data['sale_price_dates_from'] ) ? $data['sale_price_dates_from'] : get_post_meta( $product_id, '_sale_price_dates_from', true );
$date_to = isset( $data['sale_price_dates_to'] ) ? $data['sale_price_dates_to'] : get_post_meta( $product_id, '_sale_price_dates_to', true );
if ( isset( $data['sale_price_dates_from'] ) ) {
$date_from = $data['sale_price_dates_from'];
} else {
$date_from = get_post_meta( $product_id, '_sale_price_dates_from', true );
$date_from = date( 'Y-m-d', $date_from );
}
if ( isset( $data['sale_price_dates_to'] ) ) {
$date_to = $data['sale_price_dates_to'];
} else {
$date_to = get_post_meta( $product_id, '_sale_price_dates_to', TRUE );
$date_to = date( 'Y-m-d', $date_to );
}
_wc_save_product_price( $product_id, $regular_price, $sale_price, $date_from, $date_to );
@ -1834,8 +1845,19 @@ class WC_API_Products extends WC_API_Resource {
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
}
$date_from = isset( $variation['sale_price_dates_from'] ) ? $variation['sale_price_dates_from'] : get_post_meta( $variation_id, '_sale_price_dates_from', true );
$date_to = isset( $variation['sale_price_dates_to'] ) ? $variation['sale_price_dates_to'] : get_post_meta( $variation_id, '_sale_price_dates_to', true );
if ( isset( $variation['sale_price_dates_from'] ) ) {
$date_from = $variation['sale_price_dates_from'];
} else {
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
$date_from = date( 'Y-m-d', $date_from );
}
if ( isset( $variation['sale_price_dates_to'] ) ) {
$date_to = $variation['sale_price_dates_to'];
} else {
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
$date_to = date( 'Y-m-d', $date_to );
}
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );

View File

@ -977,8 +977,19 @@ class WC_API_Products extends WC_API_Resource {
$sale_price = get_post_meta( $product_id, '_sale_price', true );
}
$date_from = isset( $data['sale_price_dates_from'] ) ? $data['sale_price_dates_from'] : get_post_meta( $product_id, '_sale_price_dates_from', true );
$date_to = isset( $data['sale_price_dates_to'] ) ? $data['sale_price_dates_to'] : get_post_meta( $product_id, '_sale_price_dates_to', true );
if ( isset( $data['sale_price_dates_from'] ) ) {
$date_from = $data['sale_price_dates_from'];
} else {
$date_from = get_post_meta( $product_id, '_sale_price_dates_from', true );
$date_from = date( 'Y-m-d', $date_from );
}
if ( isset( $data['sale_price_dates_to'] ) ) {
$date_to = $data['sale_price_dates_to'];
} else {
$date_to = get_post_meta( $product_id, '_sale_price_dates_to', TRUE );
$date_to = date( 'Y-m-d', $date_to );
}
_wc_save_product_price( $product_id, $regular_price, $sale_price, $date_from, $date_to );
@ -1367,8 +1378,19 @@ class WC_API_Products extends WC_API_Resource {
$sale_price = get_post_meta( $variation_id, '_sale_price', true );
}
$date_from = isset( $variation['sale_price_dates_from'] ) ? $variation['sale_price_dates_from'] : get_post_meta( $variation_id, '_sale_price_dates_from', true );
$date_to = isset( $variation['sale_price_dates_to'] ) ? $variation['sale_price_dates_to'] : get_post_meta( $variation_id, '_sale_price_dates_to', true );
if ( isset( $variation['sale_price_dates_from'] ) ) {
$date_from = $variation['sale_price_dates_from'];
} else {
$date_from = get_post_meta( $variation_id, '_sale_price_dates_from', true );
$date_from = date( 'Y-m-d', $date_from );
}
if ( isset( $variation['sale_price_dates_to'] ) ) {
$date_to = $variation['sale_price_dates_to'];
} else {
$date_to = get_post_meta( $variation_id, '_sale_price_dates_to', true );
$date_to = date( 'Y-m-d', $date_to );
}
_wc_save_product_price( $variation_id, $regular_price, $sale_price, $date_from, $date_to );