PluginProbe
WPC Countdown Timer for WooCommerce / 3.1.6
WPC Countdown Timer for WooCommerce v3.1.6
3.2.2 3.2.1 3.2.0 2.3.2 2.3.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 3.0.0 All 55 releases
wpc-countdown-timer / wpc-countdown-timer.php

wpc-countdown-timer.php in WPC Countdown Timer for WooCommerce 3.1.6, at wpc-countdown-timer.php

1,337 lines 84.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WPC Countdown Timer for WooCommerce
4 Plugin URI: https://wpclever.net/
5 Description: WPC Countdown Timer helps you display countdown timer in single product pages and shop page.
6 Version: 3.1.6
7 Author: WPClever
8 Author URI: https://wpclever.net
9 Text Domain: wpc-countdown-timer
10 Domain Path: /languages/
11 Requires Plugins: woocommerce
12 Requires at least: 4.0
13 Tested up to: 6.8
14 WC requires at least: 3.0
15 WC tested up to: 10.3
16 License: GPLv2 or later
17 License URI: http://www.gnu.org/licenses/gpl-2.0.html
18 */
19
20 defined( 'ABSPATH' ) || exit;
21
22 ! defined( 'WOOCT_VERSION' ) && define( 'WOOCT_VERSION', '3.1.6' );
23 ! defined( 'WOOCT_LITE' ) && define( 'WOOCT_LITE', __FILE__ );
24 ! defined( 'WOOCT_FILE' ) && define( 'WOOCT_FILE', __FILE__ );
25 ! defined( 'WOOCT_URI' ) && define( 'WOOCT_URI', plugin_dir_url( __FILE__ ) );
26 ! defined( 'WOOCT_DIR' ) && define( 'WOOCT_DIR', plugin_dir_path( __FILE__ ) );
27 ! defined( 'WOOCT_SUPPORT' ) && define( 'WOOCT_SUPPORT', 'https://wpclever.net/support?utm_source=support&utm_medium=wooct&utm_campaign=wporg' );
28 ! defined( 'WOOCT_REVIEWS' ) && define( 'WOOCT_REVIEWS', 'https://wordpress.org/support/plugin/wpc-countdown-timer/reviews/' );
29 ! defined( 'WOOCT_CHANGELOG' ) && define( 'WOOCT_CHANGELOG', 'https://wordpress.org/plugins/wpc-countdown-timer/#developers' );
30 ! defined( 'WOOCT_DISCUSSION' ) && define( 'WOOCT_DISCUSSION', 'https://wordpress.org/support/plugin/wpc-countdown-timer' );
31 ! defined( 'WPC_URI' ) && define( 'WPC_URI', WOOCT_URI );
32
33 include 'includes/dashboard/wpc-dashboard.php';
34 include 'includes/kit/wpc-kit.php';
35 include 'includes/hpos.php';
36
37 if ( ! function_exists( 'wooct_init' ) ) {
38 add_action( 'plugins_loaded', 'wooct_init', 11 );
39
40 function wooct_init() {
41 if ( ! function_exists( 'WC' ) || ! version_compare( WC()->version, '3.0', '>=' ) ) {
42 add_action( 'admin_notices', 'wooct_notice_wc' );
43
44 return null;
45 }
46
47 if ( ! class_exists( 'WPCleverWooct' ) && class_exists( 'WC_Product' ) ) {
48 class WPCleverWooct {
49 protected static $instance = null;
50 protected static $settings = [];
51 protected static $localization = [];
52
53 public static function instance() {
54 if ( is_null( self::$instance ) ) {
55 self::$instance = new self();
56 }
57
58 return self::$instance;
59 }
60
61 function __construct() {
62 self::$settings = (array) get_option( 'wooct_settings', [] );
63 self::$localization = (array) get_option( 'wooct_localization', [] );
64
65 // Init
66 add_action( 'init', [ $this, 'init' ] );
67
68 // Settings
69 add_action( 'admin_init', [ $this, 'register_settings' ] );
70 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
71
72 // Enqueue scripts
73 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
74
75 // Enqueue backend scripts
76 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
77
78 // Add settings link
79 add_filter( 'plugin_action_links', [ $this, 'action_links' ], 10, 2 );
80 add_filter( 'plugin_row_meta', [ $this, 'row_meta' ], 10, 2 );
81
82 // Product data tabs
83 add_filter( 'woocommerce_product_data_tabs', [ $this, 'product_data_tabs' ] );
84 add_action( 'woocommerce_product_data_panels', [ $this, 'product_data_panels' ] );
85 add_action( 'woocommerce_process_product_meta', [ $this, 'process_product_meta' ] );
86
87 // Variation
88 add_action( 'woocommerce_product_after_variable_attributes', [
89 $this,
90 'variation_settings'
91 ], 99, 3 );
92 add_action( 'woocommerce_save_product_variation', [ $this, 'save_variation_settings' ], 99, 2 );
93 add_action( 'woocommerce_after_variations_table', [ $this, 'after_variations_table' ] );
94
95 // Product columns
96 add_filter( 'manage_edit-product_columns', [ $this, 'product_columns' ] );
97 add_action( 'manage_product_posts_custom_column', [ $this, 'product_custom_column' ], 10, 2 );
98
99 // Product class
100 add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 99, 2 );
101
102 // Countdown on archive
103 $pos_archive = self::get_setting( 'position_archive', 'above_add_to_cart' );
104
105 switch ( $pos_archive ) {
106 case 'under_title':
107 add_action( 'woocommerce_shop_loop_item_title', [ $this, 'show_countdown' ], 11 );
108 break;
109 case 'under_rating':
110 add_action( 'woocommerce_after_shop_loop_item_title', [ $this, 'show_countdown' ], 6 );
111 break;
112 case 'under_price':
113 add_action( 'woocommerce_after_shop_loop_item_title', [ $this, 'show_countdown' ], 11 );
114 break;
115 case 'above_add_to_cart':
116 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'show_countdown' ], 9 );
117 break;
118 case 'under_add_to_cart':
119 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'show_countdown' ], 11 );
120 break;
121 }
122
123 // Countdown on single
124 $pos_single = self::get_setting( 'position_single', '29' );
125
126 if ( ! empty( $pos_single ) ) {
127 add_action( 'woocommerce_single_product_summary', [
128 $this,
129 'show_countdown_single'
130 ], $pos_single );
131 }
132
133 // Shortcode
134 add_shortcode( 'wooct_product', [ $this, 'shortcode_product' ] );
135
136 // Preview
137 add_action( 'wp_ajax_wooct_preview', [ $this, 'ajax_preview' ] );
138
139 // WPC Variation Duplicator
140 add_action( 'wpcvd_duplicated', [ $this, 'duplicate_variation' ], 99, 2 );
141
142 // WPC Variation Bulk Editor
143 add_action( 'wpcvb_bulk_update_variation', [ $this, 'bulk_update_variation' ], 99, 2 );
144 }
145
146 function init() {
147 // load text-domain
148 load_plugin_textdomain( 'wpc-countdown-timer', false, basename( WOOCT_DIR ) . '/languages/' );
149 }
150
151 function register_settings() {
152 // settings
153 register_setting( 'wooct_settings', 'wooct_settings', [
154 'type' => 'array',
155 'sanitize_callback' => [ $this, 'sanitize_array' ],
156 ] );
157
158 // localization
159 register_setting( 'wooct_localization', 'wooct_localization', [
160 'type' => 'array',
161 'sanitize_callback' => [ $this, 'sanitize_array' ],
162 ] );
163 }
164
165 function admin_menu() {
166 add_submenu_page( 'wpclever', esc_html__( 'WPC Countdown Timer', 'wpc-countdown-timer' ), esc_html__( 'Countdown Timer', 'wpc-countdown-timer' ), 'manage_options', 'wpclever-wooct', [
167 $this,
168 'admin_menu_content'
169 ] );
170 }
171
172 function admin_menu_content() {
173 $active_tab = $_GET['tab'] ?? 'settings';
174 ?>
175 <div class="wpclever_settings_page wrap">
176 <div class="wpclever_settings_page_header">
177 <a class="wpclever_settings_page_header_logo" href="https://wpclever.net/"
178 target="_blank" title="Visit wpclever.net"></a>
179 <div class="wpclever_settings_page_header_text">
180 <div class="wpclever_settings_page_title"><?php echo esc_html__( 'WPC Countdown Timer', 'wpc-countdown-timer' ) . ' ' . esc_html( WOOCT_VERSION ) . ' ' . ( defined( 'WOOCT_PREMIUM' ) ? '<span class="premium" style="display: none">' . esc_html__( 'Premium', 'wpc-countdown-timer' ) . '</span>' : '' ); ?></div>
181 <div class="wpclever_settings_page_desc about-text">
182 <p>
183 <?php printf( /* translators: stars */ esc_html__( 'Thank you for using our plugin! If you are satisfied, please reward it a full five-star %s rating.', 'wpc-countdown-timer' ), '<span style="color:#ffb900">&#9733;&#9733;&#9733;&#9733;&#9733;</span>' ); ?>
184 <br/>
185 <a href="<?php echo esc_url( WOOCT_REVIEWS ); ?>"
186 target="_blank"><?php esc_html_e( 'Reviews', 'wpc-countdown-timer' ); ?></a>
187 |
188 <a href="<?php echo esc_url( WOOCT_CHANGELOG ); ?>"
189 target="_blank"><?php esc_html_e( 'Changelog', 'wpc-countdown-timer' ); ?></a>
190 |
191 <a href="<?php echo esc_url( WOOCT_DISCUSSION ); ?>"
192 target="_blank"><?php esc_html_e( 'Discussion', 'wpc-countdown-timer' ); ?></a>
193 </p>
194 </div>
195 </div>
196 </div>
197 <h2></h2>
198 <?php if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] ) { ?>
199 <div class="notice notice-success is-dismissible">
200 <p><?php esc_html_e( 'Settings updated.', 'wpc-countdown-timer' ); ?></p>
201 </div>
202 <?php } ?>
203 <div class="wpclever_settings_page_nav">
204 <h2 class="nav-tab-wrapper">
205 <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpclever-wooct&tab=settings' ) ); ?>"
206 class="<?php echo $active_tab === 'settings' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
207 <?php esc_html_e( 'Settings', 'wpc-countdown-timer' ); ?>
208 </a>
209 <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpclever-wooct&tab=localization' ) ); ?>"
210 class="<?php echo $active_tab === 'localization' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
211 <?php esc_html_e( 'Localization', 'wpc-countdown-timer' ); ?>
212 </a>
213 <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpclever-wooct&tab=shortcode' ) ); ?>"
214 class="<?php echo $active_tab === 'shortcode' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
215 <?php esc_html_e( 'Shortcode [...]', 'wpc-countdown-timer' ); ?>
216 </a>
217 <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpclever-wooct&tab=premium' ) ); ?>"
218 class="<?php echo $active_tab === 'premium' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>"
219 style="color: #c9356e">
220 <?php esc_html_e( 'Premium Version', 'wpc-countdown-timer' ); ?>
221 </a>
222 <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpclever-kit' ) ); ?>"
223 class="nav-tab">
224 <?php esc_html_e( 'Essential Kit', 'wpc-countdown-timer' ); ?>
225 </a>
226 </h2>
227 </div>
228 <div class="wpclever_settings_page_content">
229 <?php if ( $active_tab === 'settings' ) {
230 $pos_archive = self::get_setting( 'position_archive', 'above_add_to_cart' );
231 $pos_single = self::get_setting( 'position_single', '29' );
232 ?>
233 <form method="post" action="options.php">
234 <table class="form-table">
235 <tr class="heading">
236 <th colspan="2">
237 <?php esc_html_e( 'General', 'wpc-countdown-timer' ); ?>
238 </th>
239 </tr>
240 <tr>
241 <th scope="row"><?php esc_html_e( 'Position on archive', 'wpc-countdown-timer' ); ?></th>
242 <td>
243 <label> <select name="wooct_settings[position_archive]">
244 <option value="under_title" <?php selected( $pos_archive, 'under_title' ); ?>><?php esc_html_e( 'Under title', 'wpc-countdown-timer' ); ?></option>
245 <option value="under_rating" <?php selected( $pos_archive, 'under_rating' ); ?>><?php esc_html_e( 'Under rating', 'wpc-countdown-timer' ); ?></option>
246 <option value="under_price" <?php selected( $pos_archive, 'under_price' ); ?>><?php esc_html_e( 'Under price', 'wpc-countdown-timer' ); ?></option>
247 <option value="above_add_to_cart" <?php selected( $pos_archive, 'above_add_to_cart' ); ?>><?php esc_html_e( 'Above add to cart', 'wpc-countdown-timer' ); ?></option>
248 <option value="under_add_to_cart" <?php selected( $pos_archive, 'under_add_to_cart' ); ?>><?php esc_html_e( 'Under add to cart', 'wpc-countdown-timer' ); ?></option>
249 <option value="0" <?php selected( $pos_archive, '0' ); ?>><?php esc_html_e( 'None (hide it)', 'wpc-countdown-timer' ); ?></option>
250 </select> </label>
251 <p class="description"><?php echo sprintf( /* translators: shortcode */ esc_html__( 'You also can use shortcode %s to show the countdown timer for current product.', 'wpc-countdown-timer' ), '<code>[wooct_product]</code>' ); ?></p>
252 </td>
253 </tr>
254 <tr>
255 <th scope="row"><?php esc_html_e( 'Position on single', 'wpc-countdown-timer' ); ?></th>
256 <td>
257 <label> <select name="wooct_settings[position_single]">
258 <option value="6" <?php selected( $pos_single, '6' ); ?>><?php esc_html_e( 'Under title', 'wpc-countdown-timer' ); ?></option>
259 <option value="11" <?php selected( $pos_single, '11' ); ?>><?php esc_html_e( 'Under price & rating', 'wpc-countdown-timer' ); ?></option>
260 <option value="21" <?php selected( $pos_single, '21' ); ?>><?php esc_html_e( 'Under excerpt', 'wpc-countdown-timer' ); ?></option>
261 <option value="29" <?php selected( $pos_single, '29' ); ?>><?php esc_html_e( 'Above add to cart', 'wpc-countdown-timer' ); ?></option>
262 <option value="31" <?php selected( $pos_single, '31' ); ?>><?php esc_html_e( 'Under add to cart', 'wpc-countdown-timer' ); ?></option>
263 <option value="41" <?php selected( $pos_single, '41' ); ?>><?php esc_html_e( 'Under meta', 'wpc-countdown-timer' ); ?></option>
264 <option value="51" <?php selected( $pos_single, '51' ); ?>><?php esc_html_e( 'Under sharing', 'wpc-countdown-timer' ); ?></option>
265 <option value="0" <?php selected( $pos_single, '0' ); ?>><?php esc_html_e( 'None (hide it)', 'wpc-countdown-timer' ); ?></option>
266 </select> </label>
267 <p class="description"><?php echo sprintf( /* translators: shortcode */ esc_html__( 'You also can use shortcode %s to show the countdown timer for current product.', 'wpc-countdown-timer' ), '<code>[wooct_product]</code>' ); ?></p>
268 </td>
269 </tr>
270 <tr>
271 <th>
272 <?php esc_html_e( 'Default above text', 'wpc-countdown-timer' ); ?>
273 </th>
274 <td>
275 <label>
276 <input type="text" name="wooct_settings[text_above]"
277 class="large-text"
278 value="<?php echo stripslashes( self::get_setting( 'text_above' ) ); ?>"/>
279 </label>
280 </td>
281 </tr>
282 <tr>
283 <th>
284 <?php esc_html_e( 'Default under text', 'wpc-countdown-timer' ); ?>
285 </th>
286 <td>
287 <label>
288 <input type="text" name="wooct_settings[text_under]"
289 class="large-text"
290 value="<?php echo stripslashes( self::get_setting( 'text_under' ) ); ?>"/>
291 </label>
292 </td>
293 </tr>
294 <tr>
295 <th>
296 <?php esc_html_e( 'Default ended text', 'wpc-countdown-timer' ); ?>
297 </th>
298 <td>
299 <label>
300 <input type="text" name="wooct_settings[text_ended]"
301 class="large-text"
302 value="<?php echo stripslashes( self::get_setting( 'text_ended' ) ); ?>"/>
303 </label>
304 </td>
305 </tr>
306 <tr class="submit">
307 <th colspan="2">
308 <?php settings_fields( 'wooct_settings' ); ?><?php submit_button(); ?>
309 <a style="display: none;" class="wpclever_export"
310 data-key="wooct_settings"
311 data-name="settings"
312 href="#"><?php esc_html_e( 'import / export', 'wpc-countdown-timer' ); ?></a>
313 </th>
314 </tr>
315 </table>
316 </form>
317 <?php } elseif ( $active_tab === 'localization' ) {
318 $zero_plural = self::localization( 'zero_plural', 'yes' );
319 ?>
320 <form method="post" action="options.php">
321 <table class="form-table">
322 <tr class="heading">
323 <th scope="row"><?php esc_html_e( 'General', 'wpc-countdown-timer' ); ?></th>
324 <td>
325 <?php esc_html_e( 'Leave blank to use the default text and its equivalent translation in multiple languages.', 'wpc-countdown-timer' ); ?>
326 </td>
327 </tr>
328 <tr>
329 <th scope="row"><?php esc_html_e( 'Zero is plural?', 'wpc-countdown-timer' ); ?></th>
330 <td>
331 <label> <select name="wooct_localization[zero_plural]">
332 <option value="yes" <?php selected( $zero_plural, 'yes' ); ?>><?php esc_html_e( 'Yes', 'wpc-countdown-timer' ); ?></option>
333 <option value="no" <?php selected( $zero_plural, 'no' ); ?>><?php esc_html_e( 'No', 'wpc-countdown-timer' ); ?></option>
334 </select> </label>
335 </td>
336 </tr>
337 <tr>
338 <th scope="row"><?php esc_html_e( 'Day', 'wpc-countdown-timer' ); ?></th>
339 <td>
340 <label>
341 <input type="text" name="wooct_localization[day]"
342 placeholder="<?php esc_attr_e( 'Day', 'wpc-countdown-timer' ); ?>"
343 value="<?php echo esc_attr( self::localization( 'day' ) ); ?>"/>
344 </label>
345 </td>
346 </tr>
347 <tr>
348 <th scope="row"><?php esc_html_e( 'Days', 'wpc-countdown-timer' ); ?></th>
349 <td>
350 <label>
351 <input type="text" name="wooct_localization[days]"
352 placeholder="<?php esc_attr_e( 'Days', 'wpc-countdown-timer' ); ?>"
353 value="<?php echo esc_attr( self::localization( 'days' ) ); ?>"/>
354 </label>
355 </td>
356 </tr>
357 <tr>
358 <th scope="row"><?php esc_html_e( 'Hour', 'wpc-countdown-timer' ); ?></th>
359 <td>
360 <label>
361 <input type="text" name="wooct_localization[hour]"
362 placeholder="<?php esc_attr_e( 'Hour', 'wpc-countdown-timer' ); ?>"
363 value="<?php echo esc_attr( self::localization( 'hour' ) ); ?>"/>
364 </label>
365 </td>
366 </tr>
367 <tr>
368 <th scope="row"><?php esc_html_e( 'Hours', 'wpc-countdown-timer' ); ?></th>
369 <td>
370 <label>
371 <input type="text" name="wooct_localization[hours]"
372 placeholder="<?php esc_attr_e( 'Hours', 'wpc-countdown-timer' ); ?>"
373 value="<?php echo esc_attr( self::localization( 'hours' ) ); ?>"/>
374 </label>
375 </td>
376 </tr>
377 <tr>
378 <th scope="row"><?php esc_html_e( 'Minute', 'wpc-countdown-timer' ); ?></th>
379 <td>
380 <label>
381 <input type="text" name="wooct_localization[minute]"
382 placeholder="<?php esc_attr_e( 'Minute', 'wpc-countdown-timer' ); ?>"
383 value="<?php echo esc_attr( self::localization( 'minute' ) ); ?>"/>
384 </label>
385 </td>
386 </tr>
387 <tr>
388 <th scope="row"><?php esc_html_e( 'Minutes', 'wpc-countdown-timer' ); ?></th>
389 <td>
390 <label>
391 <input type="text" name="wooct_localization[minutes]"
392 placeholder="<?php esc_attr_e( 'Minutes', 'wpc-countdown-timer' ); ?>"
393 value="<?php echo esc_attr( self::localization( 'minutes' ) ); ?>"/>
394 </label>
395 </td>
396 </tr>
397 <tr>
398 <th scope="row"><?php esc_html_e( 'Second', 'wpc-countdown-timer' ); ?></th>
399 <td>
400 <label>
401 <input type="text" name="wooct_localization[second]"
402 placeholder="<?php esc_attr_e( 'Second', 'wpc-countdown-timer' ); ?>"
403 value="<?php echo esc_attr( self::localization( 'second' ) ); ?>"/>
404 </label>
405 </td>
406 </tr>
407 <tr>
408 <th scope="row"><?php esc_html_e( 'Seconds', 'wpc-countdown-timer' ); ?></th>
409 <td>
410 <label>
411 <input type="text" name="wooct_localization[seconds]"
412 placeholder="<?php esc_attr_e( 'Seconds', 'wpc-countdown-timer' ); ?>"
413 value="<?php echo esc_attr( self::localization( 'seconds' ) ); ?>"/>
414 </label>
415 </td>
416 </tr>
417 <tr class="submit">
418 <th colspan="2">
419 <?php settings_fields( 'wooct_localization' ); ?><?php submit_button(); ?>
420 <a style="display: none;" class="wpclever_export"
421 data-key="wooct_localization"
422 data-name="settings"
423 href="#"><?php esc_html_e( 'import / export', 'wpc-countdown-timer' ); ?></a>
424 </th>
425 </tr>
426 </table>
427 </form>
428 <?php } elseif ( $active_tab === 'shortcode' ) { ?>
429 <table class="form-table wooct_shortcode_builder wooct_time_form">
430 <tr>
431 <th><?php esc_html_e( 'Preview', 'wpc-countdown-timer' ); ?></th>
432 <td>
433 <div class="wooct_preview">
434 <div class="wooct_preview_inner"></div>
435 </div>
436 </td>
437 </tr>
438 <tr>
439 <th><?php esc_html_e( 'Shortcode', 'wpc-countdown-timer' ); ?></th>
440 <td>
441 <label>
442 <textarea class="wooct_shortcode" style="width: 100%"
443 readonly><?php esc_html_e( 'Configure the below options to build shortcode and you can place it where you want.', 'wpc-countdown-timer' ); ?></textarea>
444 </label>
445 <p class="description" style="color: #c9356e">
446 * This feature only available on Premium Version. Click
447 <a href="https://wpclever.net/downloads/wpc-countdown-timer?utm_source=pro&utm_medium=wooct&utm_campaign=wporg"
448 target="_blank">here</a> to buy, just $29!
449 </p>
450 </td>
451 </tr>
452 <?php self::configure_form(); ?>
453 </table>
454 <?php } elseif ( $active_tab == 'premium' ) { ?>
455 <div class="wpclever_settings_page_content_text">
456 <p>
457 Get the Premium Version just $29!
458 <a href="https://wpclever.net/downloads/wpc-countdown-timer?utm_source=pro&utm_medium=wooct&utm_campaign=wporg"
459 target="_blank">https://wpclever.net/downloads/wpc-countdown-timer</a>
460 </p>
461 <p><strong>Extra features for Premium Version:</strong></p>
462 <ul style="margin-bottom: 0">
463 <li>- Build your custom countdown timer to place everywhere you want by using
464 shortcode builder.
465 </li>
466 <li>- Configure countdown timer on a variation basis.</li>
467 <li>- Get the lifetime update & premium support.</li>
468 </ul>
469 </div>
470 <?php } ?>
471 </div><!-- /.wpclever_settings_page_content -->
472 <div class="wpclever_settings_page_suggestion">
473 <div class="wpclever_settings_page_suggestion_label">
474 <span class="dashicons dashicons-yes-alt"></span> Suggestion
475 </div>
476 <div class="wpclever_settings_page_suggestion_content">
477 <div>
478 To display custom engaging real-time messages on any wished positions, please
479 install
480 <a href="https://wordpress.org/plugins/wpc-smart-messages/" target="_blank">WPC
481 Smart Messages</a> plugin. It's free!
482 </div>
483 <div>
484 Wanna save your precious time working on variations? Try our brand-new free plugin
485 <a href="https://wordpress.org/plugins/wpc-variation-bulk-editor/" target="_blank">WPC
486 Variation Bulk Editor</a> and
487 <a href="https://wordpress.org/plugins/wpc-variation-duplicator/" target="_blank">WPC
488 Variation Duplicator</a>.
489 </div>
490 </div>
491 </div>
492 </div>
493 <?php
494 }
495
496 function configure_form( $post_id = 0, $is_variation = false ) {
497 $active = get_post_meta( $post_id, 'wooct_active', true ) ?: 'no';
498 $style = get_post_meta( $post_id, 'wooct_style', true ) ?: apply_filters( 'wooct_default_style', '01' );
499 $color = get_post_meta( $post_id, 'wooct_color', true ) ?: '#ff6600';
500 $time = get_post_meta( $post_id, 'wooct_time', true ) ?: 'custom';
501 $time_start = get_post_meta( $post_id, 'wooct_time_start', true ) ?: '';
502 $time_end = get_post_meta( $post_id, 'wooct_time_end', true ) ?: '';
503 $text_above = get_post_meta( $post_id, 'wooct_text_above', true ) ?: '';
504 $text_under = get_post_meta( $post_id, 'wooct_text_under', true ) ?: '';
505 $text_ended = get_post_meta( $post_id, 'wooct_text_ended', true ) ?: '';
506 $default_style = apply_filters( 'wooct_default_style', '01' );
507 $styles = apply_filters( 'wooct_styles', [
508 '01' => esc_html__( 'Style 01 (flat)', 'wpc-countdown-timer' ),
509 '02' => esc_html__( 'Style 02 (square)', 'wpc-countdown-timer' ),
510 '03' => esc_html__( 'Style 03 (rounded)', 'wpc-countdown-timer' ),
511 '04' => esc_html__( 'Style 04 (light flipper)', 'wpc-countdown-timer' ),
512 '05' => esc_html__( 'Style 05 (dark flipper)', 'wpc-countdown-timer' ),
513 '06' => esc_html__( 'Style 06 (rounded)', 'wpc-countdown-timer' ),
514 '07' => esc_html__( 'Style 07 (animated)', 'wpc-countdown-timer' ),
515 ] );
516
517 if ( empty( $style ) ) {
518 $style = $default_style;
519 }
520
521 if ( $is_variation ) {
522 $name = '_v[' . $post_id . ']';
523 $tr = '<p class="form-field form-row">';
524 $_tr = '</p>';
525 $th = '<label>';
526 $_th = '</label>';
527 $td = $_td = '';
528 } else {
529 $name = '';
530 $tr = '<tr>';
531 $_tr = '</tr>';
532 $th = '<th>';
533 $_th = '</th>';
534 $td = '<td>';
535 $_td = '</td>';
536 }
537
538 if ( $is_variation ) {
539 ?>
540 <p class="form-field form-row" style="color: #c9356e">
541 * This feature only available on Premium Version. Click
542 <a href="https://wpclever.net/downloads/wpc-countdown-timer?utm_source=pro&utm_medium=wooct&utm_campaign=wporg"
543 target="_blank">here</a> to buy, just $29!
544 </p>
545 <?php
546 }
547
548 if ( $post_id ) {
549 echo $tr;
550 echo $th . esc_html__( 'Active', 'wpc-countdown-timer' ) . $_th;
551 echo $td;
552 echo '<select name="' . esc_attr( 'wooct_active' . $name ) . '" class="wooct_active">';
553 echo '<option value="yes" ' . selected( $active, 'yes', false ) . '>' . esc_html__( 'Yes', 'wpc-countdown-timer' ) . '</option>';
554 echo '<option value="no" ' . selected( $active, 'no', false ) . '>' . esc_html__( 'No', 'wpc-countdown-timer' ) . '</option>';
555 echo '</select>';
556 echo $_td;
557 echo $_tr;
558
559 echo $tr;
560 echo $th . esc_html__( 'Time', 'wpc-countdown-timer' ) . $_th;
561 echo $td;
562 echo '<select name="' . esc_attr( 'wooct_time' . $name ) . '" class="wooct_time">';
563 echo '<option value="custom" ' . selected( $time, 'custom', false ) . '>' . esc_html__( 'Custom', 'wpc-countdown-timer' ) . '</option>';
564 echo '<option value="sale" ' . selected( $time, 'sale', false ) . '>' . esc_html__( 'Sale price dates', 'wpc-countdown-timer' ) . '</option>';
565 echo '</select>';
566 echo '<span class="woocommerce-help-tip" data-tip="' . esc_attr__( 'If you choose sale price dates, please check your scheduled sale price in the General tab.', 'wpc-countdown-timer' ) . '"></span>';
567 echo $_td;
568 echo $_tr;
569 }
570
571 if ( $is_variation ) {
572 echo '<p class="form-field form-row wooct_show_if_custom">';
573 } else {
574 echo '<tr class="wooct_show_if_custom">';
575 }
576
577 echo $th . esc_html__( 'Start time', 'wpc-countdown-timer' ) . $_th;
578 echo $td;
579 echo '<input name="' . esc_attr( 'wooct_time_start' . $name ) . '" value="' . esc_attr( $time_start ) . '" class="wooct_time_start wooct_date_time wooct_date_time_input wooct_picker" type="text" readonly="readonly"/>';
580 echo $_td;
581 echo $_tr;
582
583 if ( $is_variation ) {
584 echo '<p class="form-field form-row wooct_show_if_custom">';
585 } else {
586 echo '<tr class="wooct_show_if_custom">';
587 }
588
589 echo $th . esc_html__( 'End time', 'wpc-countdown-timer' ) . $_th;
590 echo $td;
591 echo '<input name="' . esc_attr( 'wooct_time_end' . $name ) . '" value="' . esc_attr( $time_end ) . '" class="wooct_time_end wooct_date_time wooct_date_time_input wooct_picker" type="text" readonly="readonly"/>';
592 echo $_td;
593 echo $_tr;
594
595 echo $tr;
596 echo $th . esc_html__( 'Above text', 'wpc-countdown-timer' ) . $_th;
597 echo $td . '<input name="' . esc_attr( 'wooct_text_above' . $name ) . '" value="' . stripslashes( $text_above ) . '" class="wooct_text_above" type="text" style="width: 100%"/>' . $_td;
598 echo $_tr;
599
600 echo $tr;
601 echo $th . esc_html__( 'Under text', 'wpc-countdown-timer' ) . $_th;
602 echo $td . '<input name="' . esc_attr( 'wooct_text_under' . $name ) . '" value="' . stripslashes( $text_under ) . '" class="wooct_text_under" type="text" style="width: 100%"/>' . $_td;
603 echo $_tr;
604
605 echo $tr;
606 echo $th . esc_html__( 'Ended text', 'wpc-countdown-timer' ) . $_th;
607 echo $td . '<input name="' . esc_attr( 'wooct_text_ended' . $name ) . '" value="' . stripslashes( $text_ended ) . '" class="wooct_text_ended" type="text" style="width: 100%"/>' . $_td;
608 echo $_tr;
609
610 echo $tr;
611 echo $th . esc_html__( 'Style', 'wpc-countdown-timer' ) . $_th;
612 echo $td . '<select name="' . esc_attr( 'wooct_style' . $name ) . '" class="wooct_style">';
613
614 foreach ( $styles as $k => $s ) {
615 echo '<option value="' . esc_attr( $k ) . '" ' . selected( $style, $k, false ) . '>' . esc_html( $s ) . '</option>';
616 }
617
618 echo '</select>' . $_td;
619 echo $_tr;
620
621 echo $tr;
622 echo $th . esc_html__( 'Color', 'wpc-countdown-timer' ) . $_th;
623 echo $td . '<input type="text" name="' . esc_attr( 'wooct_color' . $name ) . '" class="wooct_color" value="' . esc_attr( $color ) . '"/>' . $_td;
624 echo $_tr;
625 }
626
627 function shortcode_product( $attrs ) {
628 $countdown = '';
629
630 $attrs = shortcode_atts( [
631 'id' => null
632 ], $attrs, 'wooct_product' );
633
634 if ( ! $attrs['id'] ) {
635 global $product;
636
637 if ( $product && $product->get_id() ) {
638 $attrs['id'] = $product->get_id();
639 }
640 }
641
642 if ( $attrs['id'] ) {
643 $active = apply_filters( 'wooct_active', get_post_meta( $attrs['id'], 'wooct_active', true ) ?: 'no', $attrs['id'] );
644
645 if ( $active === 'yes' ) {
646 $style = get_post_meta( $attrs['id'], 'wooct_style', true ) ?: apply_filters( 'wooct_default_style', '01' );
647 $text_above = get_post_meta( $attrs['id'], 'wooct_text_above', true ) ?: self::get_setting( 'text_above', '' );
648 $text_under = get_post_meta( $attrs['id'], 'wooct_text_under', true ) ?: self::get_setting( 'text_under', '' );
649 $text_ended = get_post_meta( $attrs['id'], 'wooct_text_ended', true ) ?: self::get_setting( 'text_ended', '' );
650 $color = get_post_meta( $attrs['id'], 'wooct_color', true ) ?: self::get_setting( 'color', '#ff6600' );
651 $time = get_post_meta( $attrs['id'], 'wooct_time', true ) ?: 'custom';
652
653 if ( $time === 'sale' ) {
654 $time_start = ( $date = get_post_meta( $attrs['id'], '_sale_price_dates_from', true ) ) ? wp_date( 'm/d/Y H:i:s', $date ) : '';
655 $time_end = ( $date = get_post_meta( $attrs['id'], '_sale_price_dates_to', true ) ) ? wp_date( 'm/d/Y H:i:s', $date ) : '';
656 } else {
657 $time_start = get_post_meta( $attrs['id'], 'wooct_time_start', true ) ?: '';
658 $time_end = get_post_meta( $attrs['id'], 'wooct_time_end', true ) ?: '';
659 }
660
661 $countdown = self::get_countdown( $style, $time_start, $time_end, $text_above, $text_under, $text_ended, $color, $attrs['id'] );
662 }
663 }
664
665 return $countdown;
666 }
667
668 function show_countdown() {
669 echo do_shortcode( '[wooct_product]' );
670 }
671
672 function ajax_preview() {
673 if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'wooct-security' ) ) {
674 die( 'Permissions check failed!' );
675 }
676
677 echo self::get_countdown( $_POST['style'], $_POST['time_start'], $_POST['time_end'], $_POST['text_above'], $_POST['text_under'], $_POST['text_ended'], $_POST['color'] );
678
679 wp_die();
680 }
681
682 function show_countdown_single() {
683 global $product;
684
685 echo '<div class="wooct-wrap-single" data-id="' . esc_attr( $product->get_id() ) . '">';
686 echo do_shortcode( '[wooct_product]' );
687 echo '</div>';
688 }
689
690 function enqueue_scripts() {
691 // moment
692 wp_enqueue_script( 'moment', WOOCT_URI . 'assets/libs/moment/moment.js', [ 'jquery' ], WOOCT_VERSION, true );
693 //wp_enqueue_script( 'moment-timezone', WOOCT_URI . 'assets/libs/moment-timezone/moment-timezone-with-data.js', [ 'jquery' ], WOOCT_VERSION, true );
694
695 // jquery.countdown
696 if ( self::localization( 'zero_plural', 'yes' ) === 'yes' ) {
697 wp_enqueue_script( 'jquery.countdown', WOOCT_URI . 'assets/libs/jquery.countdown/jquery.countdown_zp.js', [ 'jquery' ], WOOCT_VERSION, true );
698 } else {
699 wp_enqueue_script( 'jquery.countdown', WOOCT_URI . 'assets/libs/jquery.countdown/jquery.countdown.js', [ 'jquery' ], WOOCT_VERSION, true );
700 }
701
702 // flipper
703 wp_enqueue_style( 'flipper', WOOCT_URI . 'assets/libs/flipper/style.css', [], WOOCT_VERSION );
704 wp_enqueue_script( 'flipper', WOOCT_URI . 'assets/libs/flipper/jquery.flipper-responsive.js', [ 'jquery' ], WOOCT_VERSION, true );
705
706 // frontend
707 wp_enqueue_style( 'wooct-frontend', WOOCT_URI . 'assets/css/frontend.css', [], WOOCT_VERSION );
708 wp_enqueue_script( 'wooct-frontend', WOOCT_URI . 'assets/js/frontend.js', [ 'jquery' ], WOOCT_VERSION, true );
709
710 // localization
711 $day = self::localization( 'day', esc_html__( 'Day', 'wpc-countdown-timer' ) );
712 $days = self::localization( 'days', esc_html__( 'Days', 'wpc-countdown-timer' ) );
713 $hour = self::localization( 'hour', esc_html__( 'Hour', 'wpc-countdown-timer' ) );
714 $hours = self::localization( 'hours', esc_html__( 'Hours', 'wpc-countdown-timer' ) );
715 $minute = self::localization( 'minute', esc_html__( 'Minute', 'wpc-countdown-timer' ) );
716 $minutes = self::localization( 'minutes', esc_html__( 'Minutes', 'wpc-countdown-timer' ) );
717 $second = self::localization( 'second', esc_html__( 'Second', 'wpc-countdown-timer' ) );
718 $seconds = self::localization( 'seconds', esc_html__( 'Seconds', 'wpc-countdown-timer' ) );
719
720 // format
721 $format_01 = '<span>%D %!D:' . $day . ',' . $days . ';</span> <span>%H</span>:<span>%M</span>:<span>%S</span>';
722 $format_02 = '<span><span>%D</span><span>%!D:' . $day . ',' . $days . ';</span></span><span><span>%H</span><span>%!H:' . $hour . ',' . $hours . ';</span></span><span><span>%M</span><span>%!M:' . $minute . ',' . $minutes . ';</span></span><span><span>%S</span><span>%!S:' . $second . ',' . $seconds . ';</span></span>';
723 $format_06 = '<span><span>%D</span><span>d</span></span><span><span>%H</span><span>h</span></span><span><span>%M</span><span>m</span></span><span><span>%S</span><span>s</span></span>';
724 $format_07 = '<div class="d c100"><span class="text"><span>%D</span><span>d</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div><div class="h c100"><span class="text"><span>%H</span><span>h</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div><div class="m c100"><span class="text"><span>%M</span><span>m</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div><div class="s c100"><span class="text"><span>%S</span><span>s</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div>';
725
726 wp_localize_script( 'wooct-frontend', 'wooct_vars', [
727 'timezone' => get_option( 'timezone_string' ),
728 'gmt_offset' => (float) get_option( 'gmt_offset' ),
729 // default
730 'timer_format' => apply_filters( 'wooct_timer_format', $format_01 ),
731 // flat
732 'timer_format_01' => apply_filters( 'wooct_timer_format_01', $format_01 ),
733 // square
734 'timer_format_02' => apply_filters( 'wooct_timer_format_02', $format_02 ),
735 // rounded
736 'timer_format_03' => apply_filters( 'wooct_timer_format_03', $format_02 ),
737 'timer_format_06' => apply_filters( 'wooct_timer_format_06', $format_06 ),
738 'timer_format_07' => apply_filters( 'wooct_timer_format_07', $format_07 ),
739 ]
740 );
741 }
742
743 function admin_enqueue_scripts() {
744 // wpcdpk
745 wp_enqueue_style( 'wpcdpk', WOOCT_URI . 'assets/libs/wpcdpk/css/datepicker.css' );
746 wp_enqueue_script( 'wpcdpk', WOOCT_URI . 'assets/libs/wpcdpk/js/datepicker.js', [ 'jquery' ], WOOCT_VERSION, true );
747
748 // moment
749 wp_enqueue_script( 'moment', WOOCT_URI . 'assets/libs/moment/moment.js', [ 'jquery' ], WOOCT_VERSION, true );
750 //wp_enqueue_script( 'moment-timezone', WOOCT_URI . 'assets/libs/moment-timezone/moment-timezone-with-data.js', [ 'jquery' ], WOOCT_VERSION, true );
751
752 // jquery.countdown
753 if ( self::localization( 'zero_plural', 'yes' ) === 'yes' ) {
754 wp_enqueue_script( 'jquery.countdown', WOOCT_URI . 'assets/libs/jquery.countdown/jquery.countdown_zp.js', [ 'jquery' ], WOOCT_VERSION, true );
755 } else {
756 wp_enqueue_script( 'jquery.countdown', WOOCT_URI . 'assets/libs/jquery.countdown/jquery.countdown.js', [ 'jquery' ], WOOCT_VERSION, true );
757 }
758
759 // flipper
760 wp_enqueue_style( 'flipper', WOOCT_URI . 'assets/libs/flipper/style.css', [], WOOCT_VERSION );
761 wp_enqueue_script( 'flipper', WOOCT_URI . 'assets/libs/flipper/jquery.flipper-responsive.js', [ 'jquery' ], WOOCT_VERSION, true );
762
763 // frontend for preview
764 wp_enqueue_style( 'wooct-frontend', WOOCT_URI . 'assets/css/frontend.css', [], WOOCT_VERSION );
765 wp_enqueue_script( 'wooct-frontend', WOOCT_URI . 'assets/js/frontend.js', [ 'jquery' ], WOOCT_VERSION, true );
766
767 // localization
768 $day = self::localization( 'day', esc_html__( 'Day', 'wpc-countdown-timer' ) );
769 $days = self::localization( 'days', esc_html__( 'Days', 'wpc-countdown-timer' ) );
770 $hour = self::localization( 'hour', esc_html__( 'Hour', 'wpc-countdown-timer' ) );
771 $hours = self::localization( 'hours', esc_html__( 'Hours', 'wpc-countdown-timer' ) );
772 $minute = self::localization( 'minute', esc_html__( 'Minute', 'wpc-countdown-timer' ) );
773 $minutes = self::localization( 'minutes', esc_html__( 'Minutes', 'wpc-countdown-timer' ) );
774 $second = self::localization( 'second', esc_html__( 'Second', 'wpc-countdown-timer' ) );
775 $seconds = self::localization( 'seconds', esc_html__( 'Seconds', 'wpc-countdown-timer' ) );
776
777 // format
778 $format_01 = '<span>%D %!D:' . $day . ',' . $days . ';</span> <span>%H</span>:<span>%M</span>:<span>%S</span>';
779 $format_02 = '<span><span>%D</span><span>%!D:' . $day . ',' . $days . ';</span></span><span><span>%H</span><span>%!H:' . $hour . ',' . $hours . ';</span></span><span><span>%M</span><span>%!M:' . $minute . ',' . $minutes . ';</span></span><span><span>%S</span><span>%!S:' . $second . ',' . $seconds . ';</span></span>';
780 $format_06 = '<span><span>%D</span><span>d</span></span><span><span>%H</span><span>h</span></span><span><span>%M</span><span>m</span></span><span><span>%S</span><span>s</span></span>';
781 $format_07 = '<div class="d c100"><span class="text"><span>%D</span><span>d</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div><div class="h c100"><span class="text"><span>%H</span><span>h</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div><div class="m c100"><span class="text"><span>%M</span><span>m</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div><div class="s c100"><span class="text"><span>%S</span><span>s</span></span><div class="slice"><div class="bar"></div><div class="fill"></div></div></div>';
782
783 // backend
784 wp_enqueue_style( 'wp-color-picker' );
785 wp_enqueue_style( 'wooct-backend', WOOCT_URI . 'assets/css/backend.css', [], WOOCT_VERSION );
786 wp_enqueue_script( 'wooct-backend', WOOCT_URI . 'assets/js/backend.js', [
787 'jquery',
788 'wp-color-picker',
789 'jquery-ui-dialog',
790 ], WOOCT_VERSION, true );
791 wp_localize_script( 'wooct-backend', 'wooct_vars', [
792 'nonce' => wp_create_nonce( 'wooct-security' ),
793 'timezone' => get_option( 'timezone_string' ),
794 'gmt_offset' => (float) get_option( 'gmt_offset' ),
795 // default
796 'timer_format' => apply_filters( 'wooct_timer_format', $format_01 ),
797 // flat
798 'timer_format_01' => apply_filters( 'wooct_timer_format_01', $format_01 ),
799 // square
800 'timer_format_02' => apply_filters( 'wooct_timer_format_02', $format_02 ),
801 // rounded
802 'timer_format_03' => apply_filters( 'wooct_timer_format_03', $format_02 ),
803 'timer_format_06' => apply_filters( 'wooct_timer_format_06', $format_06 ),
804 'timer_format_07' => apply_filters( 'wooct_timer_format_07', $format_07 ),
805 ]
806 );
807 }
808
809 function action_links( $links, $file ) {
810 static $plugin;
811
812 if ( ! isset( $plugin ) ) {
813 $plugin = plugin_basename( __FILE__ );
814 }
815
816 if ( $plugin === $file ) {
817 $settings = '<a href="' . esc_url( admin_url( 'admin.php?page=wpclever-wooct&tab=settings' ) ) . '">' . esc_html__( 'Settings', 'wpc-countdown-timer' ) . '</a>';
818 $links['premium'] = '<a href="' . esc_url( admin_url( 'admin.php?page=wpclever-wooct&tab=premium' ) ) . '">' . esc_html__( 'Premium Version', 'wpc-countdown-timer' ) . '</a>';
819 array_unshift( $links, $settings );
820 }
821
822 return (array) $links;
823 }
824
825 function row_meta( $links, $file ) {
826 static $plugin;
827
828 if ( ! isset( $plugin ) ) {
829 $plugin = plugin_basename( __FILE__ );
830 }
831
832 if ( $plugin === $file ) {
833 $row_meta = [
834 'support' => '<a href="' . esc_url( WOOCT_DISCUSSION ) . '" target="_blank">' . esc_html__( 'Community support', 'wpc-countdown-timer' ) . '</a>',
835 ];
836
837 return array_merge( $links, $row_meta );
838 }
839
840 return (array) $links;
841 }
842
843 function product_data_tabs( $tabs ) {
844 $tabs['wooct'] = [
845 'label' => esc_html__( 'Countdown', 'wpc-countdown-timer' ),
846 'target' => 'wooct_settings',
847 ];
848
849 return $tabs;
850 }
851
852 function product_data_panels() {
853 global $post, $thepostid, $product_object;
854
855 if ( $product_object instanceof WC_Product ) {
856 $product_id = $product_object->get_id();
857 } elseif ( is_numeric( $thepostid ) ) {
858 $product_id = $thepostid;
859 } elseif ( $post instanceof WP_Post ) {
860 $product_id = $post->ID;
861 } else {
862 $product_id = 0;
863 }
864
865 if ( ! $product_id ) {
866 ?>
867 <div id='wooct_settings' class='panel woocommerce_options_panel wooct_panel'>
868 <p style="padding: 0 12px; color: #c9356e"><?php esc_html_e( 'Product wasn\'t returned.', 'wpc-countdown-timer' ); ?></p>
869 </div>
870 <?php
871 return;
872 }
873 ?>
874 <div id='wooct_settings' class='panel woocommerce_options_panel wooct_panel'>
875 <div class="wooct_current_time">
876 <?php esc_html_e( 'Current time', 'wpc-countdown-timer' ); ?>
877 <code><?php echo esc_html( current_time( 'm/d/Y' ) ); ?></code>
878 <code><?php echo esc_html( current_time( 'h:i a' ) ); ?></code>
879 <a href="<?php echo esc_url( admin_url( 'options-general.php' ) ); ?>"
880 target="_blank"><?php esc_html_e( 'Date/time settings', 'wpc-countdown-timer' ); ?></a>
881 </div>
882 <div class="wooct_preview">
883 <span><?php esc_html_e( 'Preview', 'wpc-countdown-timer' ); ?></span>
884 <div class="wooct_preview_inner"></div>
885 </div>
886 <div class="wooct_table">
887 <table class="wooct_time_form">
888 <?php self::configure_form( absint( $product_id ) ); ?>
889 </table>
890 </div>
891 </div>
892 <?php
893 }
894
895 function process_product_meta( $post_id ) {
896 if ( isset( $_POST['wooct_active'] ) ) {
897 update_post_meta( $post_id, 'wooct_active', sanitize_text_field( $_POST['wooct_active'] ) );
898 } else {
899 delete_post_meta( $post_id, 'wooct_active' );
900 }
901
902 if ( isset( $_POST['wooct_time'] ) ) {
903 update_post_meta( $post_id, 'wooct_time', sanitize_text_field( $_POST['wooct_time'] ) );
904 } else {
905 delete_post_meta( $post_id, 'wooct_time' );
906 }
907
908 if ( isset( $_POST['wooct_time_start'] ) ) {
909 update_post_meta( $post_id, 'wooct_time_start', sanitize_text_field( $_POST['wooct_time_start'] ) );
910 } else {
911 delete_post_meta( $post_id, 'wooct_time_start' );
912 }
913
914 if ( isset( $_POST['wooct_time_end'] ) ) {
915 update_post_meta( $post_id, 'wooct_time_end', sanitize_text_field( $_POST['wooct_time_end'] ) );
916 } else {
917 delete_post_meta( $post_id, 'wooct_time_end' );
918 }
919
920 if ( isset( $_POST['wooct_text_above'] ) ) {
921 update_post_meta( $post_id, 'wooct_text_above', addslashes( $_POST['wooct_text_above'] ) );
922 } else {
923 delete_post_meta( $post_id, 'wooct_text_above' );
924 }
925
926 if ( isset( $_POST['wooct_text_under'] ) ) {
927 update_post_meta( $post_id, 'wooct_text_under', addslashes( $_POST['wooct_text_under'] ) );
928 } else {
929 delete_post_meta( $post_id, 'wooct_text_under' );
930 }
931
932 if ( isset( $_POST['wooct_text_ended'] ) ) {
933 update_post_meta( $post_id, 'wooct_text_ended', addslashes( $_POST['wooct_text_ended'] ) );
934 } else {
935 delete_post_meta( $post_id, 'wooct_text_ended' );
936 }
937
938 if ( isset( $_POST['wooct_style'] ) ) {
939 update_post_meta( $post_id, 'wooct_style', sanitize_text_field( $_POST['wooct_style'] ) );
940 } else {
941 delete_post_meta( $post_id, 'wooct_style' );
942 }
943
944 if ( isset( $_POST['wooct_color'] ) ) {
945 update_post_meta( $post_id, 'wooct_color', sanitize_text_field( $_POST['wooct_color'] ) );
946 } else {
947 delete_post_meta( $post_id, 'wooct_color' );
948 }
949 }
950
951 function variation_settings( $loop, $variation_data, $variation ) {
952 ?>
953 <div class="form-row form-row-full wooct-variation-settings">
954 <label><?php esc_html_e( 'WPC Countdown Timer', 'wpc-countdown-timer' ); ?></label>
955 <div class="wooct-variation-wrap wooct_time_form">
956 <?php self::configure_form( absint( $variation->ID ), true ); ?>
957 </div>
958 </div>
959 <?php
960 }
961
962 function save_variation_settings( $post_id ) {
963 if ( isset( $_POST['wooct_active_v'][ $post_id ] ) ) {
964 update_post_meta( $post_id, 'wooct_active', sanitize_text_field( $_POST['wooct_active_v'][ $post_id ] ) );
965 } else {
966 delete_post_meta( $post_id, 'wooct_active' );
967 }
968
969 if ( isset( $_POST['wooct_time_v'][ $post_id ] ) ) {
970 update_post_meta( $post_id, 'wooct_time', sanitize_text_field( $_POST['wooct_time_v'][ $post_id ] ) );
971 } else {
972 delete_post_meta( $post_id, 'wooct_time' );
973 }
974
975 if ( isset( $_POST['wooct_time_start_v'][ $post_id ] ) ) {
976 update_post_meta( $post_id, 'wooct_time_start', sanitize_text_field( $_POST['wooct_time_start_v'][ $post_id ] ) );
977 } else {
978 delete_post_meta( $post_id, 'wooct_time_start' );
979 }
980
981 if ( isset( $_POST['wooct_time_end_v'][ $post_id ] ) ) {
982 update_post_meta( $post_id, 'wooct_time_end', sanitize_text_field( $_POST['wooct_time_end_v'][ $post_id ] ) );
983 } else {
984 delete_post_meta( $post_id, 'wooct_time_end' );
985 }
986
987 if ( isset( $_POST['wooct_text_above_v'][ $post_id ] ) ) {
988 update_post_meta( $post_id, 'wooct_text_above', addslashes( $_POST['wooct_text_above_v'][ $post_id ] ) );
989 } else {
990 delete_post_meta( $post_id, 'wooct_text_above' );
991 }
992
993 if ( isset( $_POST['wooct_text_under_v'][ $post_id ] ) ) {
994 update_post_meta( $post_id, 'wooct_text_under', addslashes( $_POST['wooct_text_under_v'][ $post_id ] ) );
995 } else {
996 delete_post_meta( $post_id, 'wooct_text_under' );
997 }
998
999 if ( isset( $_POST['wooct_text_ended_v'][ $post_id ] ) ) {
1000 update_post_meta( $post_id, 'wooct_text_ended', addslashes( $_POST['wooct_text_ended_v'][ $post_id ] ) );
1001 } else {
1002 delete_post_meta( $post_id, 'wooct_text_ended' );
1003 }
1004
1005 if ( isset( $_POST['wooct_style_v'][ $post_id ] ) ) {
1006 update_post_meta( $post_id, 'wooct_style', sanitize_text_field( $_POST['wooct_style_v'][ $post_id ] ) );
1007 } else {
1008 delete_post_meta( $post_id, 'wooct_style' );
1009 }
1010
1011 if ( isset( $_POST['wooct_color_v'][ $post_id ] ) ) {
1012 update_post_meta( $post_id, 'wooct_color', sanitize_text_field( $_POST['wooct_color_v'][ $post_id ] ) );
1013 } else {
1014 delete_post_meta( $post_id, 'wooct_color' );
1015 }
1016 }
1017
1018 function after_variations_table() {
1019 global $product;
1020
1021 echo '<div class="wooct-wrap-variation" data-id="' . esc_attr( $product->get_id() ) . '"></div>';
1022 }
1023
1024 function check_time_start( $start = '' ) {
1025 if ( ! empty( $start ) ) {
1026 if ( ! is_numeric( $start ) ) {
1027 $start = strtotime( $start );
1028 }
1029
1030 if ( current_time( 'timestamp' ) < $start ) {
1031 return false;
1032 }
1033 }
1034
1035 return true;
1036 }
1037
1038 function check_time_end( $end ) {
1039 if ( ! empty( $end ) ) {
1040 if ( ! is_numeric( $end ) ) {
1041 $end = strtotime( $end );
1042 }
1043
1044 if ( current_time( 'timestamp' ) < $end ) {
1045 return true;
1046 }
1047 }
1048
1049 return false;
1050 }
1051
1052 function post_class( $classes, $product ) {
1053 if ( $product->is_type( 'variation' ) && $product->get_parent_id() ) {
1054 $product_id = $product->get_parent_id();
1055 } else {
1056 $product_id = $product->get_id();
1057 }
1058
1059 $active = get_post_meta( $product_id, 'wooct_active', true ) ?: 'no';
1060 $time = get_post_meta( $product_id, 'wooct_time', true ) ?: '';
1061
1062 if ( $time === 'sale' ) {
1063 $time_start = ( $date = get_post_meta( $product_id, '_sale_price_dates_from', true ) ) ? wp_date( 'm/d/Y H:i:s', $date ) : '';
1064 $time_end = ( $date = get_post_meta( $product_id, '_sale_price_dates_to', true ) ) ? wp_date( 'm/d/Y H:i:s', $date ) : '';
1065 } else {
1066 $time_start = get_post_meta( $product_id, 'wooct_time_start', true ) ?: '';
1067 $time_end = get_post_meta( $product_id, 'wooct_time_end', true ) ?: '';
1068 }
1069
1070 if ( $active === 'yes' ) {
1071 $classes[] = 'wooct-active';
1072 }
1073
1074 if ( ! self::check_time_end( $time_end ) ) {
1075 $classes[] = 'wooct-ended';
1076 } elseif ( self::check_time_start( $time_start ) ) {
1077 $classes[] = 'wooct-running';
1078 }
1079
1080 return $classes;
1081 }
1082
1083 function get_countdown( $style, $time_start, $time_end, $text_above, $text_under, $text_ended, $color = '', $product_id = 0 ) {
1084 $countdown = '';
1085 $css = '';
1086 $style = apply_filters( 'wooct_style', $style, $product_id );
1087 $color = apply_filters( 'wooct_color', $color, $product_id );
1088 $time_start = apply_filters( 'wooct_time_start', $time_start, $product_id );
1089 $time_end = apply_filters( 'wooct_time_end', $time_end, $product_id );
1090 $text_above = apply_filters( 'wooct_text_above', $text_above, $product_id );
1091 $text_under = apply_filters( 'wooct_text_under', $text_under, $product_id );
1092 $text_ended = apply_filters( 'wooct_text_ended', $text_ended, $product_id );
1093
1094 if ( ! $product_id ) {
1095 $key = uniqid();
1096 } else {
1097 $key = $product_id;
1098 }
1099
1100 if ( is_numeric( $time_start ) ) {
1101 $time_start = wp_date( 'm/d/Y H:i:s', $time_start );
1102 }
1103
1104 if ( is_numeric( $time_end ) ) {
1105 $time_end = wp_date( 'm/d/Y H:i:s', $time_end );
1106 }
1107
1108 if ( ! empty( $time_end ) && self::check_time_start( $time_start ) ) {
1109 if ( ! empty( $color ) ) {
1110 switch ( $style ) {
1111 case '07':
1112 $css = '.wooct-countdown.wooct-style-07.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer .c100 .bar, .wooct-countdown.wooct-style-07.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer .c100 .fill { border-color: ' . esc_attr( $color ) . '} .wooct-countdown.wooct-style-07.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer .c100 > span.text > span:first-child { color: ' . esc_attr( $color ) . '; }';
1113
1114 break;
1115 case '06':
1116 $css = '.wooct-countdown.wooct-style-06.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer > span { border-top-color: ' . esc_attr( $color ) . '; border-bottom-color: ' . esc_attr( $color ) . '; border-left-color: ' . esc_attr( $color ) . '; } .wooct-countdown.wooct-style-06.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer > span span:first-child { color: ' . esc_attr( $color ) . '; }';
1117
1118 break;
1119 case '03':
1120 $css = '.wooct-countdown.wooct-style-03.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer > span { border-color: ' . esc_attr( $color ) . '; } .wooct-countdown.wooct-style-03.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer > span span:first-child { color: ' . esc_attr( $color ) . '; }';
1121
1122 break;
1123 case '02':
1124 $css = '.wooct-countdown.wooct-style-02.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer > span { border-color: ' . esc_attr( $color ) . '; } .wooct-countdown.wooct-style-02.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer > span span:first-child { color: ' . esc_attr( $color ) . '; }';
1125
1126 break;
1127 case '01':
1128 $css = '.wooct-countdown.wooct-style-01.wooct-countdown-' . esc_attr( $key ) . ' .wooct-timer { color: ' . esc_attr( $color ) . '; }';
1129
1130 break;
1131 }
1132 }
1133
1134 if ( ! self::check_time_end( $time_end ) ) {
1135 if ( ! empty( $text_ended ) ) {
1136 $class = 'wooct-countdown wooct-countdown-' . esc_attr( $key ) . ' wooct-ended wooct-style-' . esc_attr( $style );
1137 $countdown .= '<div class="' . esc_attr( apply_filters( 'wooct_class_ended', $class ) ) . '">';
1138 $countdown .= '<div class="wooct-text-ended">' . stripslashes( $text_ended ) . '</div>';
1139
1140 if ( ! empty( $css ) ) {
1141 $countdown .= '<div class="wooct-css"><style>' . $css . '</style></div>';
1142 }
1143
1144 $countdown .= '</div>';
1145 }
1146 } else {
1147 $class = 'wooct-countdown wooct-countdown-' . esc_attr( $key ) . ' wooct-running wooct-style-' . esc_attr( $style ) . ' ' . ( $style === '04' || $style === '05' ? 'wooct-flipper' : '' );
1148 $countdown .= '<div class="' . esc_attr( apply_filters( 'wooct_class', $class ) ) . '" data-css="' . esc_attr( $css ) . '" data-style="' . esc_attr( $style ) . '" data-timer="' . esc_attr( $time_end ) . '" data-ended="' . htmlentities( stripslashes( $text_ended ) ) . '">';
1149
1150 if ( ! empty( $text_above ) ) {
1151 $countdown .= '<div class="wooct-text-above">' . stripslashes( $text_above ) . '</div>';
1152 }
1153
1154 if ( $style === '04' || $style === '05' ) {
1155 // flipper
1156 $days = self::localization( 'days', esc_html__( 'Days', 'wpc-countdown-timer' ) );
1157 $hours = self::localization( 'hours', esc_html__( 'Hours', 'wpc-countdown-timer' ) );
1158 $minutes = self::localization( 'minutes', esc_html__( 'Minutes', 'wpc-countdown-timer' ) );
1159 $seconds = self::localization( 'seconds', esc_html__( 'Seconds', 'wpc-countdown-timer' ) );
1160 $template = apply_filters( 'wooct_flipper_template', 'dd|HH|ii|ss' );
1161 $labels = apply_filters( 'wooct_flipper_labels', $days . '|' . $hours . '|' . $minutes . '|' . $seconds );
1162 $countdown .= '<div class="wooct-timer flipper ' . ( $style === '05' ? 'flipper-dark' : '' ) . '" data-reverse="true" data-datetime="' . esc_attr( $time_end ) . '" data-template="' . esc_attr( $template ) . '" data-labels="' . esc_attr( $labels ) . '"></div>';
1163 } else {
1164 $countdown .= '<div class="wooct-timer">' . $time_end . '</div>';
1165 }
1166
1167 if ( ! empty( $text_under ) ) {
1168 $countdown .= '<div class="wooct-text-under">' . stripslashes( $text_under ) . '</div>';
1169 }
1170
1171 if ( ! empty( $css ) ) {
1172 $countdown .= '<div class="wooct-css"><style>' . $css . '</style></div>';
1173 }
1174
1175 $countdown .= '</div>';
1176 }
1177 }
1178
1179 return apply_filters( 'wooct_countdown', $countdown, $style, $time_start, $time_end, $text_above, $text_under, $text_ended, $color, $product_id );
1180 }
1181
1182 function product_columns( $columns ) {
1183 $columns['wooct'] = esc_html__( 'Countdown', 'wpc-countdown-timer' );
1184
1185 return $columns;
1186 }
1187
1188 function product_custom_column( $column, $postid ) {
1189 if ( $column === 'wooct' ) {
1190 $active = get_post_meta( $postid, 'wooct_active', true ) ?: 'no';
1191 $time_start = get_post_meta( $postid, 'wooct_time_start', true ) ?: '';
1192 $time_end = get_post_meta( $postid, 'wooct_time_end', true ) ?: '';
1193
1194 if ( ( $active === 'yes' ) && ! empty( $time_end ) ) {
1195 if ( self::check_time_start( $time_start ) && self::check_time_end( $time_end ) ) {
1196 echo '<span class="wooct-icon running"><span class="dashicons dashicons-clock"></span></span>';
1197 } else {
1198 echo '<span class="wooct-icon"><span class="dashicons dashicons-clock"></span></span>';
1199 }
1200 }
1201 }
1202 }
1203
1204 function duplicate_variation( $old_variation_id, $new_variation_id ) {
1205 if ( $active = get_post_meta( $old_variation_id, 'wooct_active', true ) ) {
1206 update_post_meta( $new_variation_id, 'wooct_active', $active );
1207 }
1208
1209 if ( $time = get_post_meta( $old_variation_id, 'wooct_time', true ) ) {
1210 update_post_meta( $new_variation_id, 'wooct_time', $time );
1211 }
1212
1213 if ( $time_start = get_post_meta( $old_variation_id, 'wooct_time_start', true ) ) {
1214 update_post_meta( $new_variation_id, 'wooct_time_start', $time_start );
1215 }
1216
1217 if ( $time_end = get_post_meta( $old_variation_id, 'wooct_time_end', true ) ) {
1218 update_post_meta( $new_variation_id, 'wooct_time_end', $time_end );
1219 }
1220
1221 if ( $text_above = get_post_meta( $old_variation_id, 'wooct_text_above', true ) ) {
1222 update_post_meta( $new_variation_id, 'wooct_text_above', $text_above );
1223 }
1224
1225 if ( $text_under = get_post_meta( $old_variation_id, 'wooct_text_under', true ) ) {
1226 update_post_meta( $new_variation_id, 'wooct_text_under', $text_under );
1227 }
1228
1229 if ( $text_ended = get_post_meta( $old_variation_id, 'wooct_text_ended', true ) ) {
1230 update_post_meta( $new_variation_id, 'wooct_text_ended', $text_ended );
1231 }
1232
1233 if ( $style = get_post_meta( $old_variation_id, 'wooct_style', true ) ) {
1234 update_post_meta( $new_variation_id, 'wooct_style', $style );
1235 }
1236
1237 if ( $style = get_post_meta( $old_variation_id, 'wooct_color', true ) ) {
1238 update_post_meta( $new_variation_id, 'wooct_color', $style );
1239 }
1240 }
1241
1242 function bulk_update_variation( $variation_id, $fields ) {
1243 if ( ! empty( $fields['wooct_active_v'] ) && ( $fields['wooct_active_v'] !== 'wpcvb_no_change' ) ) {
1244 update_post_meta( $variation_id, 'wooct_active', sanitize_text_field( $fields['wooct_active_v'] ) );
1245 }
1246
1247 if ( ! empty( $fields['wooct_time_v'] ) && ( $fields['wooct_time_v'] !== 'wpcvb_no_change' ) ) {
1248 update_post_meta( $variation_id, 'wooct_time', sanitize_text_field( $fields['wooct_time_v'] ) );
1249 }
1250
1251 if ( ! empty( $fields['wooct_time_start_v'] ) ) {
1252 update_post_meta( $variation_id, 'wooct_time_start', sanitize_text_field( $fields['wooct_time_start_v'] ) );
1253 }
1254
1255 if ( ! empty( $fields['wooct_time_end_v'] ) ) {
1256 update_post_meta( $variation_id, 'wooct_time_end', sanitize_text_field( $fields['wooct_time_end_v'] ) );
1257 }
1258
1259 if ( ! empty( $fields['wooct_text_above_v'] ) ) {
1260 update_post_meta( $variation_id, 'wooct_text_above', sanitize_text_field( $fields['wooct_text_above_v'] ) );
1261 }
1262
1263 if ( ! empty( $fields['wooct_text_under_v'] ) ) {
1264 update_post_meta( $variation_id, 'wooct_text_under', sanitize_text_field( $fields['wooct_text_under_v'] ) );
1265 }
1266
1267 if ( ! empty( $fields['wooct_text_ended_v'] ) ) {
1268 update_post_meta( $variation_id, 'wooct_text_ended', sanitize_text_field( $fields['wooct_text_ended_v'] ) );
1269 }
1270
1271 if ( ! empty( $fields['wooct_style_v'] ) && ( $fields['wooct_style_v'] !== 'wpcvb_no_change' ) ) {
1272 update_post_meta( $variation_id, 'wooct_style', sanitize_text_field( $fields['wooct_style_v'] ) );
1273 }
1274
1275 if ( ! empty( $fields['wooct_color_v'] ) && ( $fields['wooct_color_v'] !== 'wpcvb_no_change' ) ) {
1276 update_post_meta( $variation_id, 'wooct_color', sanitize_text_field( $fields['wooct_color_v'] ) );
1277 }
1278 }
1279
1280 function sanitize_array( $arr ) {
1281 foreach ( (array) $arr as $k => $v ) {
1282 if ( is_array( $v ) ) {
1283 $arr[ $k ] = self::sanitize_array( $v );
1284 } else {
1285 $arr[ $k ] = sanitize_post_field( 'post_content', $v, 0, 'db' );
1286 }
1287 }
1288
1289 return $arr;
1290 }
1291
1292 public static function get_settings() {
1293 return apply_filters( 'wooct_get_settings', self::$settings );
1294 }
1295
1296 public static function get_setting( $name, $default = false ) {
1297 if ( ! empty( self::$settings ) && isset( self::$settings[ $name ] ) ) {
1298 $setting = self::$settings[ $name ];
1299 } else {
1300 $setting = get_option( 'wooct_' . $name, $default );
1301 }
1302
1303 return apply_filters( 'wooct_get_setting', $setting, $name, $default );
1304 }
1305
1306 public static function localization( $key = '', $default = '' ) {
1307 if ( ! empty( $key ) && ! empty( self::$localization[ $key ] ) ) {
1308 $str = self::$localization[ $key ];
1309 } else {
1310 $str = get_option( 'wooct_localization_' . $key );
1311
1312 if ( empty( $str ) ) {
1313 $str = $default;
1314 }
1315 }
1316
1317 return apply_filters( 'wooct_localization_' . $key, $str );
1318 }
1319 }
1320
1321 return WPCleverWooct::instance();
1322 }
1323
1324 return null;
1325 }
1326 }
1327
1328 if ( ! function_exists( 'wooct_notice_wc' ) ) {
1329 function wooct_notice_wc() {
1330 ?>
1331 <div class="error">
1332 <p><strong>WPC Countdown Timer</strong> require WooCommerce version 3.0 or greater.</p>
1333 </div>
1334 <?php
1335 }
1336 }
1337