Skip to content

Commit

Permalink
fix: schedule product price is not working correctly (#612)
Browse files Browse the repository at this point in the history
* fix: schedule product price is not working correctly

* refactor: dokan_is_store_open function

* refactor: check if store open colse time is set
  • Loading branch information
saimonh3 authored and Sabbir Ahmed committed Apr 26, 2019
1 parent 3eb1740 commit 1102483
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 24 deletions.
8 changes: 1 addition & 7 deletions classes/template-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ function handle_product_add() {
}

if ( $date_to ) {
update_post_meta( $product_id, '_sale_price_dates_to', strtotime( $date_to ) );
update_post_meta( $product_id, '_sale_price_dates_to', strtotime( '+23 hours', strtotime( $date_to ) ) );
} else {
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
Expand All @@ -315,12 +315,6 @@ function handle_product_add() {
if ( '' !== $postdata['_sale_price'] && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $postdata['_sale_price'] ) );
}

if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', ( $postdata['_regular_price'] === '' ) ? '' : wc_format_decimal( $postdata['_regular_price'] ) );
update_post_meta( $product_id, '_sale_price_dates_from', '' );
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
}

update_post_meta( $product_id, '_visibility', 'visible' );
Expand Down
2 changes: 1 addition & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3154,7 +3154,7 @@ function dokan_is_store_open( $user_id ) {
$open_days = isset( $store_info['dokan_store_time'] ) ? $store_info['dokan_store_time'] : '';
$today = strtolower( date( 'l' ) );

if ( ! is_array( $open_days ) && ! isset( $open_days[ $today ] ) ) {
if ( ! isset( $open_days[ $today ] ) ) {
return false;
}

Expand Down
8 changes: 1 addition & 7 deletions includes/product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function dokan_save_product( $args ) {
}

if ( $date_to ) {
update_post_meta( $product_id, '_sale_price_dates_to', strtotime( $date_to ) );
update_post_meta( $product_id, '_sale_price_dates_to', strtotime( '+ 23 hours', strtotime( $date_to ) ) );
} else {
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}
Expand All @@ -148,12 +148,6 @@ function dokan_save_product( $args ) {
update_post_meta( $product_id, '_price', wc_format_decimal( $data['_sale_price'] ) );
}

if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $product_id, '_price', ( $data['_regular_price'] === '' ) ? '' : wc_format_decimal( $data['_regular_price'] ) );
update_post_meta( $product_id, '_sale_price_dates_from', '' );
update_post_meta( $product_id, '_sale_price_dates_to', '' );
}

if ( array_key_exists( $data['_visibility'], dokan_get_product_visibility_options() ) ) {
update_post_meta( $product_id, '_visibility', sanitize_text_field( $data['_visibility'] ) );
} else {
Expand Down
11 changes: 3 additions & 8 deletions includes/wc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ function dokan_process_product_meta( $post_id, $data = [] ) {

// Dates
update_post_meta( $post_id, '_sale_price_dates_from', $date_from ? strtotime( $date_from ) : '' );
update_post_meta( $post_id, '_sale_price_dates_to', $date_to ? strtotime( $date_to ) : '' );

// error_log( var_export( date('y-m-d H:i:s'), true ) );
update_post_meta( $post_id, '_sale_price_dates_to', $date_to ? strtotime( '+ 23 hours', strtotime( $date_to ) ): '' );

if ( $date_to && ! $date_from ) {
$date_from = date( 'Y-m-d' );
Expand All @@ -261,13 +263,6 @@ function dokan_process_product_meta( $post_id, $data = [] ) {
} else {
update_post_meta( $post_id, '_price', '' === $regular_price ? '' : wc_format_decimal( $regular_price ) );
}

if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $post_id, '_price', '' === $regular_price ? '' : wc_format_decimal( $regular_price ) );
update_post_meta( $post_id, '_sale_price', '' );
update_post_meta( $post_id, '_sale_price_dates_from', '' );
update_post_meta( $post_id, '_sale_price_dates_to', '' );
}
}

//enable reviews
Expand Down
5 changes: 4 additions & 1 deletion templates/settings/store-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,10 @@
<label class="dokan-w3 control-label"></label>
<div class="dokan-w6" style="width: auto">
<?php foreach ( $dokan_days as $key => $day ) : ?>
<?php $status = isset( $all_times[$day]['open'] ) ? $all_times[$day]['open'] : $all_times[$day]['status']; ?>
<?php
$status = isset( $all_times[$day]['status'] ) ? $all_times[$day]['status'] : '';
$status = isset( $all_times[$day]['open'] ) ? $all_times[$day]['open'] : $status;
?>
<div class="dokan-form-group">
<label class="day control-label" for="<?php echo esc_attr( $day ) ?>-opening-time">
<?php echo esc_html( dokan_get_translated_days( $day ) ); ?>
Expand Down

0 comments on commit 1102483

Please sign in to comment.