| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Class Name: SALES_COUNTDOWN_TIMER_Product |
| 5 |
Author: Andy Ha (support@villatheme.com) |
| 6 |
Author URI: https://villatheme.com |
| 7 |
Copyright 2017 villatheme.com. All rights reserved. |
| 8 |
*/ |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
class SALES_COUNTDOWN_TIMER_Admin_Product { |
| 14 |
protected $settings; |
| 15 |
protected $data; |
| 16 |
|
| 17 |
function __construct() { |
| 18 |
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) { |
| 19 |
$this->settings = new SALES_COUNTDOWN_TIMER_Data(); |
| 20 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 99 ); |
| 21 |
|
| 22 |
add_action( 'woocommerce_process_product_meta_simple', array( |
| 23 |
$this, |
| 24 |
'woocommerce_process_product_meta_simple' |
| 25 |
) ); |
| 26 |
add_action( 'woocommerce_process_product_meta_external', array( |
| 27 |
$this, |
| 28 |
'woocommerce_process_product_meta_simple', |
| 29 |
) ); |
| 30 |
|
| 31 |
add_action( 'woocommerce_process_product_meta_easy_product_bundle', array( $this, 'woocommerce_process_product_meta_simple' ) ); |
| 32 |
|
| 33 |
add_action( 'woocommerce_save_product_variation', array( |
| 34 |
$this, |
| 35 |
'woocommerce_save_product_variation' |
| 36 |
), 10, 2 ); |
| 37 |
|
| 38 |
add_action( 'woocommerce_product_write_panel_tabs', array( |
| 39 |
$this, |
| 40 |
'woocommerce_product_write_panel_tabs' |
| 41 |
) ); |
| 42 |
add_action( 'woocommerce_variation_options', array( $this, 'woocommerce_variation_options' ) ); |
| 43 |
add_action( 'woocommerce_product_options_pricing', array( |
| 44 |
$this, |
| 45 |
'woocommerce_product_options_pricing' |
| 46 |
), 99 ); |
| 47 |
add_action( 'woocommerce_variation_options_pricing', array( |
| 48 |
$this, |
| 49 |
'woocommerce_variation_options_pricing' |
| 50 |
), 10, 3 ); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
public function admin_enqueue_scripts() { |
| 56 |
$screen = get_current_screen(); |
| 57 |
$suffix = WP_DEBUG ? '' : '.min'; |
| 58 |
if ( $screen->id == 'product' ) { |
| 59 |
wp_enqueue_script( 'sales-countdown-timer-admin-product', SALES_COUNTDOWN_TIMER_JS . 'sales-countdown-timer-admin-product' . $suffix . '.js', array( 'jquery' ), SALES_COUNTDOWN_TIMER_VERSION, false ); |
| 60 |
wp_enqueue_style( 'sales-countdown-timer-admin-product', SALES_COUNTDOWN_TIMER_CSS . 'sales-countdown-timer-admin-product' . $suffix . '.css', [], SALES_COUNTDOWN_TIMER_VERSION ); |
| 61 |
/*update price*/ |
| 62 |
// global $post; |
| 63 |
// $product_id = $post->ID; |
| 64 |
// $product = wc_get_product( $product_id ); |
| 65 |
// if ( $product ) { |
| 66 |
// if ( $product->is_type( 'variable' ) ) { |
| 67 |
// $variations = $product->get_children(); |
| 68 |
// if ( is_array( $variations ) && count( $variations ) ) { |
| 69 |
// foreach ( $variations as $variation_key => $variation_id ) { |
| 70 |
// $variation = wc_get_product( $variation_id ); |
| 71 |
// if ( $variation ) { |
| 72 |
// if ( ! $variation->get_sale_price( 'edit' ) ) { |
| 73 |
// continue; |
| 74 |
// } |
| 75 |
// if ( $variation->get_regular_price( 'edit' ) != $variation->get_price( 'edit' ) ) { |
| 76 |
// if ( $variation->get_date_on_sale_from( 'edit' ) && $variation->get_date_on_sale_from( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) < $variation->get_date_on_sale_from( 'edit' )->getTimestamp() ) { |
| 77 |
// update_post_meta( $variation_id, '_price', $variation->get_regular_price( 'edit' ) ); |
| 78 |
// $variation->set_price( $variation->get_regular_price( 'edit' ) ); |
| 79 |
// } |
| 80 |
// } |
| 81 |
// if ( $variation->get_date_on_sale_to( 'edit' ) && $variation->get_date_on_sale_to( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) > $variation->get_date_on_sale_to( 'edit' )->getTimestamp() ) { |
| 82 |
// update_post_meta( $variation_id, '_sale_price_old_woo_ctr', $variation->get_sale_price( 'edit' ) ); |
| 83 |
// $regular_price = $variation->get_regular_price(); |
| 84 |
// $variation->set_price( $regular_price ); |
| 85 |
// $variation->set_sale_price( '' ); |
| 86 |
// $variation->set_date_on_sale_to( '' ); |
| 87 |
// $variation->set_date_on_sale_from( '' ); |
| 88 |
// $variation->save(); |
| 89 |
// delete_post_meta( $variation_id, '_woo_ctr_product_sold_quantity' ); |
| 90 |
// } |
| 91 |
// } |
| 92 |
// } |
| 93 |
// } |
| 94 |
// |
| 95 |
// } else { |
| 96 |
// if ( ! $product->get_sale_price( 'edit' ) ) { |
| 97 |
// return; |
| 98 |
// } |
| 99 |
// if ( $product->get_regular_price( 'edit' ) != $product->get_price( 'edit' ) ) { |
| 100 |
// if ( $product->get_date_on_sale_from( 'edit' ) && $product->get_date_on_sale_from( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) < $product->get_date_on_sale_from( 'edit' )->getTimestamp() ) { |
| 101 |
// update_post_meta( $product_id, '_price', $product->get_regular_price( 'edit' ) ); |
| 102 |
// $product->set_price( $product->get_regular_price( 'edit' ) ); |
| 103 |
// } |
| 104 |
// } |
| 105 |
// if ( $product->get_date_on_sale_to( 'edit' ) && $product->get_date_on_sale_to( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) > $product->get_date_on_sale_to( 'edit' )->getTimestamp() ) { |
| 106 |
// update_post_meta( $product_id, '_sale_price_old_woo_ctr', $product->get_sale_price( 'edit' ) ); |
| 107 |
// $regular_price = $product->get_regular_price(); |
| 108 |
// $product->set_price( $regular_price ); |
| 109 |
// $product->set_sale_price( '' ); |
| 110 |
// $product->set_date_on_sale_to( '' ); |
| 111 |
// $product->set_date_on_sale_from( '' ); |
| 112 |
// $product->save(); |
| 113 |
// delete_post_meta( $product_id, '_woo_ctr_product_sold_quantity' ); |
| 114 |
// } |
| 115 |
// } |
| 116 |
// } |
| 117 |
} elseif ( $screen->id == 'edit-product' ) { |
| 118 |
/*update price*/ |
| 119 |
global $wp_query; |
| 120 |
$products = $wp_query->get_posts(); |
| 121 |
if ( count( $products ) ) { |
| 122 |
foreach ( $products as $product_obj ) { |
| 123 |
$product_id = $product_obj->ID; |
| 124 |
$product = wc_get_product( $product_id ); |
| 125 |
if ( $product ) { |
| 126 |
if ( $product->is_type( 'variable' ) ) { |
| 127 |
$variations = $product->get_children(); |
| 128 |
if ( is_array( $variations ) && count( $variations ) ) { |
| 129 |
foreach ( $variations as $variation_key => $variation_id ) { |
| 130 |
$variation = wc_get_product( $variation_id ); |
| 131 |
if ( $variation ) { |
| 132 |
if ( ! $variation->get_sale_price( 'edit' ) ) { |
| 133 |
continue; |
| 134 |
} |
| 135 |
if ( $variation->get_regular_price( 'edit' ) != $variation->get_price( 'edit' ) ) { |
| 136 |
if ( $variation->get_date_on_sale_from( 'edit' ) && $variation->get_date_on_sale_from( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) < $variation->get_date_on_sale_from( 'edit' )->getTimestamp() ) { |
| 137 |
update_post_meta( $variation_id, '_price', $variation->get_regular_price( 'edit' ) ); |
| 138 |
$variation->set_price( $variation->get_regular_price( 'edit' ) ); |
| 139 |
} |
| 140 |
} |
| 141 |
if ( $variation->get_date_on_sale_to( 'edit' ) && $variation->get_date_on_sale_to( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) > $variation->get_date_on_sale_to( 'edit' )->getTimestamp() ) { |
| 142 |
update_post_meta( $variation_id, '_sale_price_old_woo_ctr', $variation->get_sale_price( 'edit' ) ); |
| 143 |
$regular_price = $variation->get_regular_price(); |
| 144 |
$variation->set_price( $regular_price ); |
| 145 |
$variation->set_sale_price( '' ); |
| 146 |
$variation->set_date_on_sale_to( '' ); |
| 147 |
$variation->set_date_on_sale_from( '' ); |
| 148 |
$variation->save(); |
| 149 |
delete_post_meta( $variation_id, '_woo_ctr_product_sold_quantity' ); |
| 150 |
} |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
} else { |
| 156 |
if ( ! $product->get_sale_price( 'edit' ) ) { |
| 157 |
continue; |
| 158 |
} |
| 159 |
if ( $product->get_regular_price( 'edit' ) != $product->get_price( 'edit' ) ) { |
| 160 |
if ( $product->get_date_on_sale_from( 'edit' ) && $product->get_date_on_sale_from( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) < $product->get_date_on_sale_from( 'edit' )->getTimestamp() ) { |
| 161 |
update_post_meta( $product_id, '_price', $product->get_regular_price( 'edit' ) ); |
| 162 |
$product->set_price( $product->get_regular_price( 'edit' ) ); |
| 163 |
} |
| 164 |
} |
| 165 |
if ( $product->get_date_on_sale_to( 'edit' ) && $product->get_date_on_sale_to( 'edit' )->getTimestamp() && current_time( 'timestamp', true ) > $product->get_date_on_sale_to( 'edit' )->getTimestamp() ) { |
| 166 |
update_post_meta( $product_id, '_sale_price_old_woo_ctr', $product->get_sale_price( 'edit' ) ); |
| 167 |
$regular_price = $product->get_regular_price(); |
| 168 |
$product->set_price( $regular_price ); |
| 169 |
$product->set_sale_price( '' ); |
| 170 |
$product->set_date_on_sale_to( '' ); |
| 171 |
$product->set_date_on_sale_from( '' ); |
| 172 |
$product->save(); |
| 173 |
delete_post_meta( $product_id, '_woo_ctr_product_sold_quantity' ); |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
public function woocommerce_product_write_panel_tabs() { |
| 184 |
ob_start(); |
| 185 |
} |
| 186 |
|
| 187 |
public function woocommerce_variation_options() { |
| 188 |
ob_start(); |
| 189 |
} |
| 190 |
|
| 191 |
public function woocommerce_product_options_pricing() { |
| 192 |
global $post; |
| 193 |
$html = ob_get_clean(); |
| 194 |
preg_match_all( '/<p class=\"form-field sale_price_dates_fields\"(.+?)<\/p>/si', $html, $datefields ); |
| 195 |
$html = str_replace( $datefields[0], '', $html ); |
| 196 |
echo $html;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 197 |
$product_object = wc_get_product( $post->ID ); |
| 198 |
$sale_from = $product_object->get_date_on_sale_from( 'edit' ) ? $product_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() : 0; |
| 199 |
$sale_to = $product_object->get_date_on_sale_to( 'edit' ) ? $product_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() : 0; |
| 200 |
$sale_price_dates_from = $sale_from ? date_i18n( 'Y-m-d', $sale_from ) : ''; |
| 201 |
$sale_price_dates_to = $sale_to ? date_i18n( 'Y-m-d', $sale_to ) : ''; |
| 202 |
$sale_price_time_from = $sale_from % 86400; |
| 203 |
$sale_price_time_to = $sale_to % 86400; |
| 204 |
|
| 205 |
echo '<p class="form-field sale_price_dates_field"> |
| 206 |
<label for="_sale_price_dates_from">' . esc_html__( 'Sale price dates and times', 'sales-countdown-timer' ) . '</label> |
| 207 |
<input type="text" class="short" name="_sale_price_dates_from" id="_sale_price_dates_from" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . esc_html( esc_html_x( 'From…', 'placeholder', 'sales-countdown-timer' ) ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" /> |
| 208 |
<input type="time" name="_sale_price_times_from" id="sale_price_times_from" value="' . esc_attr( woo_ctr_time_revert( $sale_price_time_from ) ) . '"> |
| 209 |
<input type="text" class="short" name="_sale_price_dates_to" id="_sale_price_dates_to" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . esc_html( esc_html_x( 'To…', 'placeholder', 'sales-countdown-timer' ) ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" /> |
| 210 |
<input type="time" name="_sale_price_times_to" id="sale_price_times_to" value="' . esc_attr( woo_ctr_time_revert( $sale_price_time_to ) ) . '"> |
| 211 |
<a href="#" class="description cancel_sale_schedule">' . esc_html__( 'Cancel', 'sales-countdown-timer' ) . '</a>' . wc_help_tip( esc_html__( 'Dates and times value are set in your website timezone.', 'sales-countdown-timer' ) ) .// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 212 |
'</p>'; |
| 213 |
echo '<div class="woo-sctr-countdown-timer-admin-product">'; |
| 214 |
$id = $this->settings->get_id(); |
| 215 |
$options = array(); |
| 216 |
foreach ( $id as $k => $v ) { |
| 217 |
$options[ $v ] = $this->settings->get_names()[ $k ]; |
| 218 |
} |
| 219 |
woocommerce_wp_select( |
| 220 |
array( |
| 221 |
'id' => '_woo_ctr_select_countdown_timer', |
| 222 |
'value' => $product_object->get_meta( '_woo_ctr_select_countdown_timer', true ), |
| 223 |
'label' => esc_html__( 'Countdown timer profile', 'sales-countdown-timer' ), |
| 224 |
'options' => $options, |
| 225 |
'desc_tip' => 'true', |
| 226 |
'description' => esc_html__( 'Select countdown timer settings.', 'sales-countdown-timer' ), |
| 227 |
) |
| 228 |
); |
| 229 |
woocommerce_wp_checkbox( |
| 230 |
array( |
| 231 |
'id' => '_woo_ctr_enable_progress_bar', |
| 232 |
'label' => esc_html__( 'Enable progress bar', 'sales-countdown-timer' ), |
| 233 |
'value' => wc_bool_to_string( $product_object->get_meta( '_woo_ctr_enable_progress_bar', true ) ), |
| 234 |
) |
| 235 |
); |
| 236 |
echo '<p class="form-field"><label for="_woo_ctr_progress_bar_goal">' . esc_html__( 'Goal', 'sales-countdown-timer' ) . '</label><input type="number" value="' . ( $product_object->get_meta( '_woo_ctr_progress_bar_goal', true ) ? esc_attr( ( $product_object->get_meta( '_woo_ctr_progress_bar_goal', true ) ) ) : '' ) . '" min="0" name="_woo_ctr_progress_bar_goal" id="_woo_ctr_progress_bar_goal">' . wc_help_tip( esc_html__( 'Your product goal', 'sales-countdown-timer' ) ) . '</p>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 237 |
echo '<p class="form-field"><label for="_woo_ctr_progress_bar_initial">' . esc_html__( 'Initial quantity', 'sales-countdown-timer' ) . '</label><input type="number" value="' . ( $product_object->get_meta( '_woo_ctr_progress_bar_initial', true ) ? esc_attr( ( $product_object->get_meta( '_woo_ctr_progress_bar_initial', true ) ) ) : '' ) . '" min="0" name="_woo_ctr_progress_bar_initial" id="_woo_ctr_progress_bar_initial">' . wc_help_tip( esc_html__( 'This is the virtual quantity of sold products', 'sales-countdown-timer' ) ) . '</p>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 238 |
echo '</div>'; |
| 239 |
} |
| 240 |
|
| 241 |
public function woocommerce_variation_options_pricing( $loop, $variation_data, $variation ) { |
| 242 |
$html = ob_get_clean(); |
| 243 |
preg_match_all( '/<div class=\"form-field sale_price_dates_fields hidden\"(.+?)<\/div>/si', $html, $datefields ); |
| 244 |
$html = str_replace( $datefields[0], '', $html ); |
| 245 |
echo $html;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 246 |
$variation_object = wc_get_product( $variation->ID ); |
| 247 |
$sale_from = $variation_object->get_date_on_sale_from( 'edit' ) ? $variation_object->get_date_on_sale_from( 'edit' )->getOffsetTimestamp() : 0; |
| 248 |
$sale_to = $variation_object->get_date_on_sale_to( 'edit' ) ? $variation_object->get_date_on_sale_to( 'edit' )->getOffsetTimestamp() : 0; |
| 249 |
$sale_price_dates_from = $sale_from ? date_i18n( 'Y-m-d', $sale_from ) : ''; |
| 250 |
$sale_price_dates_to = $sale_to ? date_i18n( 'Y-m-d', $sale_to ) : ''; |
| 251 |
$sale_price_time_from = $sale_from % 86400; |
| 252 |
$sale_price_time_to = $sale_to % 86400; |
| 253 |
|
| 254 |
echo '<div class="form-field sale_price_dates_field hidden"> |
| 255 |
<p class="form-row form-row-first"> |
| 256 |
<label>' . esc_html__( 'Sale start date', 'sales-countdown-timer' ) . '</label> |
| 257 |
<input type="text" class="sale_price_dates_from" name="variable_sale_price_dates_from[' . esc_attr( $loop ) . ']" value="' . esc_attr( $sale_price_dates_from ) . '" placeholder="' . esc_html_x( 'From…', 'placeholder', 'sales-countdown-timer' ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" /> |
| 258 |
<input type="time" name="variable_sale_price_times_from[' . esc_attr( $loop ) . ']" class="variable_sale_price_times_from" value="' . esc_attr( woo_ctr_time_revert( $sale_price_time_from ) ) . '"> |
| 259 |
</p> |
| 260 |
<p class="form-row form-row-last"> |
| 261 |
<label>' . esc_html__( 'Sale end date', 'sales-countdown-timer' ) . '</label> |
| 262 |
<input type="text" class="sale_price_dates_to" name="variable_sale_price_dates_to[' . esc_attr( esc_attr( $loop ) ) . ']" value="' . esc_attr( $sale_price_dates_to ) . '" placeholder="' . esc_html_x( 'To…', 'placeholder', 'sales-countdown-timer' ) . ' YYYY-MM-DD" maxlength="10" pattern="' . esc_attr( apply_filters( 'woocommerce_date_input_html_pattern', '[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])' ) ) . '" /> |
| 263 |
<input type="time" name="variable_sale_price_times_to[' . esc_attr( $loop ) . ']" class="variable_sale_price_times_to" value="' . esc_attr( woo_ctr_time_revert( $sale_price_time_to ) ) . '"> |
| 264 |
</p> |
| 265 |
</div>'; |
| 266 |
echo '<div class="woo-sctr-countdown-timer-admin-product">'; |
| 267 |
$id = $this->settings->get_id(); |
| 268 |
$options = array(); |
| 269 |
foreach ( $id as $k => $v ) { |
| 270 |
$options[ $v ] = $this->settings->get_names()[ $k ]; |
| 271 |
} |
| 272 |
woocommerce_wp_select( |
| 273 |
array( |
| 274 |
'id' => '_woo_ctr_select_countdown_timer' . $loop, |
| 275 |
'name' => '_woo_ctr_select_countdown_timer[' . $loop . ']', |
| 276 |
'value' => $variation_object->get_meta( '_woo_ctr_select_countdown_timer', true ), |
| 277 |
'label' => esc_html__( 'Countdown timer profile', 'sales-countdown-timer' ), |
| 278 |
'options' => $options, |
| 279 |
'desc_tip' => 'true', |
| 280 |
'description' => esc_html__( 'Select countdown timer settings.', 'sales-countdown-timer' ), |
| 281 |
) |
| 282 |
); |
| 283 |
woocommerce_wp_checkbox( |
| 284 |
array( |
| 285 |
'id' => '_woo_ctr_enable_progress_bar' . $loop, |
| 286 |
'name' => '_woo_ctr_enable_progress_bar[' . $loop . ']', |
| 287 |
'label' => esc_html__( 'Enable progress bar', 'sales-countdown-timer' ), |
| 288 |
'value' => wc_bool_to_string( $variation_object->get_meta( '_woo_ctr_enable_progress_bar', true ) ), |
| 289 |
) |
| 290 |
); |
| 291 |
echo '<p class="form-field form-row form-row-first"><label for="_woo_ctr_progress_bar_goal' . esc_attr( $loop ) . '">' . esc_html__( 'Goal', 'sales-countdown-timer' ) . '</label>' . wc_help_tip( esc_html__( 'Your product goal', 'sales-countdown-timer' ) ) . '<input type="number" value="' . ( $variation_object->get_meta( '_woo_ctr_progress_bar_goal', true ) ? esc_attr( ( $variation_object->get_meta( '_woo_ctr_progress_bar_goal', true ) ) ) : '' ) . '" min="0" name="_woo_ctr_progress_bar_goal[' . esc_attr( $loop ) . ']" id="_woo_ctr_progress_bar_goal' . esc_attr( $loop ) . '"></p>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 292 |
echo '<p class="form-field form-row form-row-last"><label for="_woo_ctr_progress_bar_initial' . esc_attr( $loop ) . '">' . esc_html__( 'Initial quantity', 'sales-countdown-timer' ) . '</label>' . wc_help_tip( esc_html__( 'This is the virtual quantity of sold products', 'sales-countdown-timer' ) ) . '<input type="number" value="' . ( $variation_object->get_meta( '_woo_ctr_progress_bar_initial', true ) ? esc_attr( ( $variation_object->get_meta( '_woo_ctr_progress_bar_initial', true ) ) ) : '' ) . '" min="0" name="_woo_ctr_progress_bar_initial[' . esc_attr( $loop ) . ']" id="_woo_ctr_progress_bar_initial' . esc_attr( $loop ) . '"></p>';// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 293 |
echo '</div>'; |
| 294 |
} |
| 295 |
|
| 296 |
public function woocommerce_process_product_meta_simple( $post_id ) { |
| 297 |
if ( isset( $_REQUEST['_woo_ctr_admin_nonce'] ) && ! wp_verify_nonce( wc_clean( wp_unslash( $_REQUEST['_woo_ctr_admin_nonce'] ) ), 'woo_ctr_admin_nonce' ) ) { |
| 298 |
return; |
| 299 |
} |
| 300 |
$gmt_offset = get_option( 'gmt_offset' ); |
| 301 |
$date_on_sale_from = isset( $_POST['_sale_price_dates_from'] ) ? strtotime( sanitize_text_field( $_POST['_sale_price_dates_from'] ) ) : ''; |
| 302 |
$date_on_sale_to = isset( $_POST['_sale_price_dates_to'] ) ? strtotime( sanitize_text_field( $_POST['_sale_price_dates_to'] ) ) : ''; |
| 303 |
$sale_price_times_from = isset( $_POST['_sale_price_times_from'] ) ? woo_ctr_time( sanitize_text_field( $_POST['_sale_price_times_from'] ) ) : ''; |
| 304 |
$sale_price_times_to = isset( $_POST['_sale_price_times_to'] ) ? woo_ctr_time( sanitize_text_field( $_POST['_sale_price_times_to'] ) ) : ''; |
| 305 |
if ( $date_on_sale_from ) { |
| 306 |
$date_on_sale_from += $sale_price_times_from; |
| 307 |
} elseif ( $date_on_sale_to ) { |
| 308 |
$date_on_sale_from = strtotime( gmdate( "Y-m-d" ) ); |
| 309 |
} |
| 310 |
if ( $date_on_sale_to ) { |
| 311 |
$date_on_sale_to += $sale_price_times_to; |
| 312 |
} |
| 313 |
update_post_meta( $post_id, '_sale_price_dates_from', ( $date_on_sale_from - $gmt_offset * 3600 ) > 0 ? ( $date_on_sale_from - $gmt_offset * 3600 ) : '' ); |
| 314 |
update_post_meta( $post_id, '_sale_price_dates_to', ( $date_on_sale_to - $gmt_offset * 3600 ) > 0 ? ( $date_on_sale_to - $gmt_offset * 3600 ) : '' ); |
| 315 |
update_post_meta( $post_id, '_sale_price_times_from', isset( $_POST['_sale_price_times_from'] ) ? sanitize_text_field( $_POST['_sale_price_times_from'] ) : '00:00' ); |
| 316 |
update_post_meta( $post_id, '_sale_price_times_to', isset( $_POST['_sale_price_times_to'] ) ? sanitize_text_field( $_POST['_sale_price_times_to'] ) : '00:00' ); |
| 317 |
update_post_meta( $post_id, '_woo_ctr_select_countdown_timer', isset( $_POST['_woo_ctr_select_countdown_timer'] ) ? sanitize_text_field( $_POST['_woo_ctr_select_countdown_timer'] ) : '' ); |
| 318 |
update_post_meta( $post_id, '_woo_ctr_enable_progress_bar', isset( $_POST['_woo_ctr_enable_progress_bar'] ) ? sanitize_text_field( $_POST['_woo_ctr_enable_progress_bar'] ) : '' ); |
| 319 |
update_post_meta( $post_id, '_woo_ctr_progress_bar_goal', isset( $_POST['_woo_ctr_progress_bar_goal'] ) ? sanitize_text_field( $_POST['_woo_ctr_progress_bar_goal'] ) : '' ); |
| 320 |
update_post_meta( $post_id, '_woo_ctr_progress_bar_initial', isset( $_POST['_woo_ctr_progress_bar_initial'] ) ? sanitize_text_field( $_POST['_woo_ctr_progress_bar_initial'] ) : '' ); |
| 321 |
} |
| 322 |
|
| 323 |
public function woocommerce_save_product_variation( $variation_id, $i ) { |
| 324 |
if ( isset( $_REQUEST['_woo_ctr_admin_nonce'] ) && ! wp_verify_nonce( wc_clean( wp_unslash( $_REQUEST['_woo_ctr_admin_nonce'] ) ), 'woo_ctr_admin_nonce' ) ) { |
| 325 |
return; |
| 326 |
} |
| 327 |
global $post; |
| 328 |
update_post_meta( $variation_id, '_woo_ctr_select_countdown_timer', isset( $_POST['_woo_ctr_select_countdown_timer'][ $i ] ) ? sanitize_text_field( $_POST['_woo_ctr_select_countdown_timer'][ $i ] ) : '' ); |
| 329 |
$gmt_offset = get_option( 'gmt_offset' ); |
| 330 |
$date_on_sale_from = isset( $_POST['variable_sale_price_dates_from'][ $i ] ) ? strtotime( sanitize_text_field( $_POST['variable_sale_price_dates_from'][ $i ] ) ) : ''; |
| 331 |
$date_on_sale_to = isset( $_POST['variable_sale_price_dates_to'][ $i ] ) ? strtotime( sanitize_text_field( $_POST['variable_sale_price_dates_to'][ $i ] ) ) : ''; |
| 332 |
$sale_price_times_from = isset( $_POST['variable_sale_price_times_from'][ $i ] ) ? sanitize_text_field( $_POST['variable_sale_price_times_from'][ $i ] ) : '00:00'; |
| 333 |
$sale_price_times_to = isset( $_POST['variable_sale_price_times_to'][ $i ] ) ? sanitize_text_field( $_POST['variable_sale_price_times_to'][ $i ] ) : '00:00'; |
| 334 |
$time_from = woo_ctr_time( $sale_price_times_from ); |
| 335 |
$time_to = woo_ctr_time( $sale_price_times_to ); |
| 336 |
if ( $date_on_sale_from ) { |
| 337 |
$date_on_sale_from += $time_from; |
| 338 |
} else { |
| 339 |
$date_on_sale_from = strtotime( gmdate( "Y-m-d" ) ); |
| 340 |
$sale_price_times_from = '00:00'; |
| 341 |
} |
| 342 |
if ( $date_on_sale_to ) { |
| 343 |
$date_on_sale_to += $time_to; |
| 344 |
} |
| 345 |
$expire = $date_on_sale_from - current_time( 'timestamp' ); |
| 346 |
if ( isset( $_POST['variable_sale_price'][ $i ] ) && $_POST['variable_sale_price'][ $i ] && $date_on_sale_from && $expire > 0 ) { |
| 347 |
set_transient( 'woo_sctr_update_variable_price_start_sale_' . $variation_id, $date_on_sale_from, $expire ); |
| 348 |
} |
| 349 |
update_post_meta( $variation_id, '_sale_price_dates_from', ( $date_on_sale_from - $gmt_offset * 3600 ) > 0 ? ( $date_on_sale_from - $gmt_offset * 3600 ) : '' ); |
| 350 |
update_post_meta( $variation_id, '_sale_price_dates_to', ! empty( $date_on_sale_to ) && ( $date_on_sale_to - $gmt_offset * 3600 ) > 0 ? ( $date_on_sale_to - $gmt_offset * 3600 ) : '' ); |
| 351 |
update_post_meta( $variation_id, '_woo_ctr_select_countdown_timer', isset( $_POST['_woo_ctr_select_countdown_timer'] ) ? sanitize_text_field( $_POST['_woo_ctr_select_countdown_timer'][ $i ] ) : '' ); |
| 352 |
update_post_meta( $variation_id, '_sale_price_times_from', $sale_price_times_from ); |
| 353 |
update_post_meta( $variation_id, '_sale_price_times_to', $sale_price_times_to ); |
| 354 |
update_post_meta( $variation_id, '_woo_ctr_enable_progress_bar', isset( $_POST['_woo_ctr_enable_progress_bar'][ $i ] ) ? sanitize_text_field( $_POST['_woo_ctr_enable_progress_bar'][ $i ] ) : '' ); |
| 355 |
update_post_meta( $variation_id, '_woo_ctr_progress_bar_goal', isset( $_POST['_woo_ctr_progress_bar_goal'][ $i ] ) ? sanitize_text_field( $_POST['_woo_ctr_progress_bar_goal'][ $i ] ) : '' ); |
| 356 |
update_post_meta( $variation_id, '_woo_ctr_progress_bar_initial', isset( $_POST['_woo_ctr_progress_bar_initial'][ $i ] ) ? sanitize_text_field( $_POST['_woo_ctr_progress_bar_initial'][ $i ] ) : '' ); |
| 357 |
} |
| 358 |
|
| 359 |
} |
| 360 |
|