PluginProbe
WPC Countdown Timer for WooCommerce / 2.6.5
WPC Countdown Timer for WooCommerce v2.6.5
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 2.6.5, at wpc-countdown-timer.php

1,073 lines 48.8 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: 2.6.5
7 Author: WPClever
8 Author URI: https://wpclever.net
9 Text Domain: wpc-countdown-timer
10 Domain Path: /languages/
11 Requires at least: 4.0
12 Tested up to: 6.2
13 WC requires at least: 3.0
14 WC tested up to: 7.8
15 */
16
17 use Automattic\WooCommerce\Utilities\FeaturesUtil;
18
19 defined( 'ABSPATH' ) || exit;
20
21 ! defined( 'WOOCT_VERSION' ) && define( 'WOOCT_VERSION', '2.6.5' );
22 ! defined( 'WOOCT_FILE' ) && define( 'WOOCT_FILE', __FILE__ );
23 ! defined( 'WOOCT_URI' ) && define( 'WOOCT_URI', plugin_dir_url( __FILE__ ) );
24 ! defined( 'WOOCT_DIR' ) && define( 'WOOCT_DIR', plugin_dir_path( __FILE__ ) );
25 ! defined( 'WOOCT_SUPPORT' ) && define( 'WOOCT_SUPPORT', 'https://wpclever.net/support?utm_source=support&utm_medium=wooct&utm_campaign=wporg' );
26 ! defined( 'WOOCT_REVIEWS' ) && define( 'WOOCT_REVIEWS', 'https://wordpress.org/support/plugin/wpc-countdown-timer/reviews/?filter=5' );
27 ! defined( 'WOOCT_CHANGELOG' ) && define( 'WOOCT_CHANGELOG', 'https://wordpress.org/plugins/wpc-countdown-timer/#developers' );
28 ! defined( 'WOOCT_DISCUSSION' ) && define( 'WOOCT_DISCUSSION', 'https://wordpress.org/support/plugin/wpc-countdown-timer' );
29 ! defined( 'WPC_URI' ) && define( 'WPC_URI', WOOCT_URI );
30
31 include 'includes/dashboard/wpc-dashboard.php';
32 include 'includes/kit/wpc-kit.php';
33
34 if ( ! function_exists( 'wooct_init' ) ) {
35 add_action( 'plugins_loaded', 'wooct_init', 11 );
36
37 function wooct_init() {
38 // load text-domain
39 load_plugin_textdomain( 'wpc-countdown-timer', false, basename( __DIR__ ) . '/languages/' );
40
41 if ( ! function_exists( 'WC' ) || ! version_compare( WC()->version, '3.0', '>=' ) ) {
42 add_action( 'admin_notices', 'wooct_notice_wc' );
43
44 return;
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 // Settings
66 add_action( 'admin_init', [ $this, 'register_settings' ] );
67 add_action( 'admin_menu', [ $this, 'admin_menu' ] );
68
69 // Enqueue scripts
70 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
71
72 // Enqueue backend scripts
73 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
74
75 // Add settings link
76 add_filter( 'plugin_action_links', [ $this, 'action_links' ], 10, 2 );
77 add_filter( 'plugin_row_meta', [ $this, 'row_meta' ], 10, 2 );
78
79 // Product data tabs
80 add_filter( 'woocommerce_product_data_tabs', [ $this, 'product_data_tabs' ] );
81 add_action( 'woocommerce_product_data_panels', [ $this, 'product_data_panels' ] );
82 add_action( 'woocommerce_process_product_meta', [ $this, 'process_product_meta' ] );
83
84 // Variation
85 add_action( 'woocommerce_product_after_variable_attributes', [
86 $this,
87 'variation_settings'
88 ], 99, 3 );
89 add_action( 'woocommerce_save_product_variation', [ $this, 'save_variation_settings' ], 99, 2 );
90 add_action( 'woocommerce_after_variations_table', [ $this, 'after_variations_table' ] );
91
92 // Product columns
93 add_filter( 'manage_edit-product_columns', [ $this, 'product_columns' ] );
94 add_action( 'manage_product_posts_custom_column', [ $this, 'product_custom_column' ], 10, 2 );
95
96 // Product class
97 add_filter( 'woocommerce_post_class', [ $this, 'post_class' ], 99, 2 );
98
99 // Countdown on archive
100 $pos_archive = self::get_setting( 'position_archive', 'above_add_to_cart' );
101
102 switch ( $pos_archive ) {
103 case 'under_title':
104 add_action( 'woocommerce_shop_loop_item_title', [ $this, 'show_countdown' ], 11 );
105 break;
106 case 'under_rating':
107 add_action( 'woocommerce_after_shop_loop_item_title', [ $this, 'show_countdown' ], 6 );
108 break;
109 case 'under_price':
110 add_action( 'woocommerce_after_shop_loop_item_title', [ $this, 'show_countdown' ], 11 );
111 break;
112 case 'above_add_to_cart':
113 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'show_countdown' ], 9 );
114 break;
115 case 'under_add_to_cart':
116 add_action( 'woocommerce_after_shop_loop_item', [ $this, 'show_countdown' ], 11 );
117 break;
118 }
119
120 // Countdown on single
121 $pos_single = self::get_setting( 'position_single', '29' );
122
123 if ( ! empty( $pos_single ) ) {
124 add_action( 'woocommerce_single_product_summary', [
125 $this,
126 'show_countdown_single'
127 ], $pos_single );
128 }
129
130 // Shortcode
131 add_shortcode( 'wooct_product', [ $this, 'shortcode_product' ] );
132
133 // WPC Variation Duplicator
134 add_action( 'wpcvd_duplicated', [ $this, 'duplicate_variation' ], 99, 2 );
135
136 // WPC Variation Bulk Editor
137 add_action( 'wpcvb_bulk_update_variation', [ $this, 'bulk_update_variation' ], 99, 2 );
138
139 // HPOS compatibility
140 add_action( 'before_woocommerce_init', function () {
141 if ( class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) ) {
142 FeaturesUtil::declare_compatibility( 'custom_order_tables', WOOCT_FILE );
143 }
144 } );
145 }
146
147 function register_settings() {
148 // settings
149 register_setting( 'wooct_settings', 'wooct_settings' );
150
151 // localization
152 register_setting( 'wooct_localization', 'wooct_localization' );
153 }
154
155 function admin_menu() {
156 add_submenu_page( 'wpclever', esc_html__( 'WPC Countdown Timer', 'wpc-countdown-timer' ), esc_html__( 'Countdown Timer', 'wpc-countdown-timer' ), 'manage_options', 'wpclever-wooct', [
157 $this,
158 'admin_menu_content'
159 ] );
160 }
161
162 function admin_menu_content() {
163 $active_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'settings';
164 ?>
165 <div class="wpclever_settings_page wrap">
166 <h1 class="wpclever_settings_page_title"><?php echo esc_html__( 'WPC Countdown Timer', 'wpc-countdown-timer' ) . ' ' . WOOCT_VERSION; ?></h1>
167 <div class="wpclever_settings_page_desc about-text">
168 <p>
169 <?php printf( 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>' ); ?>
170 <br/>
171 <a href="<?php echo esc_url( WOOCT_REVIEWS ); ?>" target="_blank"><?php esc_html_e( 'Reviews', 'wpc-countdown-timer' ); ?></a> |
172 <a href="<?php echo esc_url( WOOCT_CHANGELOG ); ?>" target="_blank"><?php esc_html_e( 'Changelog', 'wpc-countdown-timer' ); ?></a> |
173 <a href="<?php echo esc_url( WOOCT_DISCUSSION ); ?>" target="_blank"><?php esc_html_e( 'Discussion', 'wpc-countdown-timer' ); ?></a>
174 </p>
175 </div>
176 <?php if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] ) { ?>
177 <div class="notice notice-success is-dismissible">
178 <p><?php esc_html_e( 'Settings updated.', 'wpc-countdown-timer' ); ?></p>
179 </div>
180 <?php } ?>
181 <div class="wpclever_settings_page_nav">
182 <h2 class="nav-tab-wrapper">
183 <a href="<?php echo admin_url( 'admin.php?page=wpclever-wooct&tab=how' ); ?>" class="<?php echo $active_tab === 'how' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
184 <?php esc_html_e( 'How to use?', 'wpc-countdown-timer' ); ?>
185 </a>
186 <a href="<?php echo admin_url( 'admin.php?page=wpclever-wooct&tab=settings' ); ?>" class="<?php echo $active_tab === 'settings' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
187 <?php esc_html_e( 'Settings', 'wpc-countdown-timer' ); ?>
188 </a>
189 <a href="<?php echo admin_url( 'admin.php?page=wpclever-wooct&tab=localization' ); ?>" class="<?php echo $active_tab === 'localization' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
190 <?php esc_html_e( 'Localization', 'wpc-countdown-timer' ); ?>
191 </a>
192 <a href="<?php echo admin_url( 'admin.php?page=wpclever-wooct&tab=shortcode' ); ?>" class="<?php echo $active_tab === 'shortcode' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>">
193 <?php esc_html_e( 'Shortcode', 'wpc-countdown-timer' ); ?>
194 </a>
195 <a href="<?php echo admin_url( 'admin.php?page=wpclever-wooct&tab=premium' ); ?>" class="<?php echo $active_tab === 'premium' ? 'nav-tab nav-tab-active' : 'nav-tab'; ?>" style="color: #c9356e">
196 <?php esc_html_e( 'Premium Version', 'wpc-countdown-timer' ); ?>
197 </a>
198 <a href="<?php echo admin_url( 'admin.php?page=wpclever-kit' ); ?>" class="nav-tab">
199 <?php esc_html_e( 'Essential Kit', 'wpc-countdown-timer' ); ?>
200 </a>
201 </h2>
202 </div>
203 <div class="wpclever_settings_page_content">
204 <?php if ( $active_tab === 'how' ) { ?>
205 <div class="wpclever_settings_page_content_text">
206 <p>
207 <?php esc_html_e( 'When adding/editing the product you can choose the "Countdown" tab then add your countdown timer.', 'wpc-countdown-timer' ); ?>
208 </p>
209 </div>
210 <?php } elseif ( $active_tab === 'settings' ) {
211 $pos_archive = self::get_setting( 'position_archive', 'above_add_to_cart' );
212 $pos_single = self::get_setting( 'position_single', '29' );
213 ?>
214 <form method="post" action="options.php">
215 <table class="form-table">
216 <tr class="heading">
217 <th colspan="2">
218 <?php esc_html_e( 'General', 'wpc-countdown-timer' ); ?>
219 </th>
220 </tr>
221 <tr>
222 <th scope="row"><?php esc_html_e( 'Position on archive', 'wpc-countdown-timer' ); ?></th>
223 <td>
224 <select name="wooct_settings[position_archive]">
225 <option value="under_title" <?php selected( $pos_archive, 'under_title' ); ?>><?php esc_html_e( 'Under title', 'wpc-countdown-timer' ); ?></option>
226 <option value="under_rating" <?php selected( $pos_archive, 'under_rating' ); ?>><?php esc_html_e( 'Under rating', 'wpc-countdown-timer' ); ?></option>
227 <option value="under_price" <?php selected( $pos_archive, 'under_price' ); ?>><?php esc_html_e( 'Under price', 'wpc-countdown-timer' ); ?></option>
228 <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>
229 <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>
230 <option value="0" <?php selected( $pos_archive, '0' ); ?>><?php esc_html_e( 'None (hide it)', 'wpc-countdown-timer' ); ?></option>
231 </select>
232 <span class="description"><?php echo sprintf( esc_html__( 'You also can use shortcode %s to show the countdown timer for current product.', 'wpc-countdown-timer' ), '<code>[wooct_product]</code>' ); ?></span>
233 </td>
234 </tr>
235 <tr>
236 <th scope="row"><?php esc_html_e( 'Position on single', 'wpc-countdown-timer' ); ?></th>
237 <td>
238 <select name="wooct_settings[position_single]">
239 <option value="6" <?php selected( $pos_single, '6' ); ?>><?php esc_html_e( 'Under title', 'wpc-countdown-timer' ); ?></option>
240 <option value="11" <?php selected( $pos_single, '11' ); ?>><?php esc_html_e( 'Under price & rating', 'wpc-countdown-timer' ); ?></option>
241 <option value="21" <?php selected( $pos_single, '21' ); ?>><?php esc_html_e( 'Under excerpt', 'wpc-countdown-timer' ); ?></option>
242 <option value="29" <?php selected( $pos_single, '29' ); ?>><?php esc_html_e( 'Above add to cart', 'wpc-countdown-timer' ); ?></option>
243 <option value="31" <?php selected( $pos_single, '31' ); ?>><?php esc_html_e( 'Under add to cart', 'wpc-countdown-timer' ); ?></option>
244 <option value="41" <?php selected( $pos_single, '41' ); ?>><?php esc_html_e( 'Under meta', 'wpc-countdown-timer' ); ?></option>
245 <option value="51" <?php selected( $pos_single, '51' ); ?>><?php esc_html_e( 'Under sharing', 'wpc-countdown-timer' ); ?></option>
246 <option value="0" <?php selected( $pos_single, '0' ); ?>><?php esc_html_e( 'None (hide it)', 'wpc-countdown-timer' ); ?></option>
247 </select>
248 <span class="description"><?php echo sprintf( esc_html__( 'You also can use shortcode %s to show the countdown timer for current product.', 'wpc-countdown-timer' ), '<code>[wooct_product]</code>' ); ?></span>
249 </td>
250 </tr>
251 <tr>
252 <th>
253 <?php esc_html_e( 'Default above text', 'wpc-countdown-timer' ); ?>
254 </th>
255 <td>
256 <input type="text" name="wooct_settings[text_above]" class="large-text" value="<?php echo stripslashes( self::get_setting( 'text_above' ) ); ?>"/>
257 </td>
258 </tr>
259 <tr>
260 <th>
261 <?php esc_html_e( 'Default under text', 'wpc-countdown-timer' ); ?>
262 </th>
263 <td>
264 <input type="text" name="wooct_settings[text_under]" class="large-text" value="<?php echo stripslashes( self::get_setting( 'text_under' ) ); ?>"/>
265 </td>
266 </tr>
267 <tr>
268 <th>
269 <?php esc_html_e( 'Default ended text', 'wpc-countdown-timer' ); ?>
270 </th>
271 <td>
272 <input type="text" name="wooct_settings[text_ended]" class="large-text" value="<?php echo stripslashes( self::get_setting( 'text_ended' ) ); ?>"/>
273 </td>
274 </tr>
275 <tr class="heading">
276 <th colspan="2"><?php esc_html_e( 'Suggestion', 'wpc-countdown-timer' ); ?></th>
277 </tr>
278 <tr>
279 <td colspan="2">
280 To display custom engaging real-time messages on any wished positions, please install
281 <a href="https://wordpress.org/plugins/wpc-smart-messages/" target="_blank">WPC Smart Messages for WooCommerce</a> plugin. It's free!
282 </td>
283 </tr>
284 <tr>
285 <td colspan="2">
286 Wanna save your precious time working on variations? Try our brand-new free plugin
287 <a href="https://wordpress.org/plugins/wpc-variation-bulk-editor/" target="_blank">WPC Variation Bulk Editor</a> and
288 <a href="https://wordpress.org/plugins/wpc-variation-duplicator/" target="_blank">WPC Variation Duplicator</a>.
289 </td>
290 </tr>
291 <tr class="submit">
292 <th colspan="2">
293 <?php settings_fields( 'wooct_settings' );
294 submit_button(); ?>
295 </th>
296 </tr>
297 </table>
298 </form>
299 <?php } elseif ( $active_tab === 'localization' ) {
300 $zero_plural = self::localization( 'zero_plural', 'yes' );
301 ?>
302 <form method="post" action="options.php">
303 <table class="form-table">
304 <tr class="heading">
305 <th scope="row"><?php esc_html_e( 'Localization', 'wpc-countdown-timer' ); ?></th>
306 <td>
307 <?php esc_html_e( 'Leave blank to use the default text and its equivalent translation in multiple languages.', 'wpc-countdown-timer' ); ?>
308 </td>
309 </tr>
310 <tr>
311 <th scope="row"><?php esc_html_e( 'Zero is plural?', 'wpc-countdown-timer' ); ?></th>
312 <td>
313 <select name="wooct_localization[zero_plural]">
314 <option value="yes" <?php selected( $zero_plural, 'yes' ); ?>><?php esc_html_e( 'Yes', 'wpc-countdown-timer' ); ?></option>
315 <option value="no" <?php selected( $zero_plural, 'no' ); ?>><?php esc_html_e( 'No', 'wpc-countdown-timer' ); ?></option>
316 </select>
317 </td>
318 </tr>
319 <tr>
320 <th scope="row"><?php esc_html_e( 'Day', 'wpc-countdown-timer' ); ?></th>
321 <td>
322 <input type="text" name="wooct_localization[day]" placeholder="<?php esc_attr_e( 'Day', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'day' ) ); ?>"/>
323 </td>
324 </tr>
325 <tr>
326 <th scope="row"><?php esc_html_e( 'Days', 'wpc-countdown-timer' ); ?></th>
327 <td>
328 <input type="text" name="wooct_localization[days]" placeholder="<?php esc_attr_e( 'Days', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'days' ) ); ?>"/>
329 </td>
330 </tr>
331 <tr>
332 <th scope="row"><?php esc_html_e( 'Hour', 'wpc-countdown-timer' ); ?></th>
333 <td>
334 <input type="text" name="wooct_localization[hour]" placeholder="<?php esc_attr_e( 'Hour', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'hour' ) ); ?>"/>
335 </td>
336 </tr>
337 <tr>
338 <th scope="row"><?php esc_html_e( 'Hours', 'wpc-countdown-timer' ); ?></th>
339 <td>
340 <input type="text" name="wooct_localization[hours]" placeholder="<?php esc_attr_e( 'Hours', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'hours' ) ); ?>"/>
341 </td>
342 </tr>
343 <tr>
344 <th scope="row"><?php esc_html_e( 'Minute', 'wpc-countdown-timer' ); ?></th>
345 <td>
346 <input type="text" name="wooct_localization[minute]" placeholder="<?php esc_attr_e( 'Minute', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'minute' ) ); ?>"/>
347 </td>
348 </tr>
349 <tr>
350 <th scope="row"><?php esc_html_e( 'Minutes', 'wpc-countdown-timer' ); ?></th>
351 <td>
352 <input type="text" name="wooct_localization[minutes]" placeholder="<?php esc_attr_e( 'Minutes', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'minutes' ) ); ?>"/>
353 </td>
354 </tr>
355 <tr>
356 <th scope="row"><?php esc_html_e( 'Second', 'wpc-countdown-timer' ); ?></th>
357 <td>
358 <input type="text" name="wooct_localization[second]" placeholder="<?php esc_attr_e( 'Second', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'second' ) ); ?>"/>
359 </td>
360 </tr>
361 <tr>
362 <th scope="row"><?php esc_html_e( 'Seconds', 'wpc-countdown-timer' ); ?></th>
363 <td>
364 <input type="text" name="wooct_localization[seconds]" placeholder="<?php esc_attr_e( 'Seconds', 'wpc-countdown-timer' ); ?>" value="<?php echo esc_attr( self::localization( 'seconds' ) ); ?>"/>
365 </td>
366 </tr>
367 <tr class="submit">
368 <th colspan="2">
369 <?php settings_fields( 'wooct_localization' );
370 submit_button(); ?>
371 </th>
372 </tr>
373 </table>
374 </form>
375 <?php } elseif ( $active_tab === 'shortcode' ) { ?>
376 <table class="form-table wooct_shortcode_builder wooct_time_form">
377 <tr class="heading">
378 <th><?php esc_html_e( 'Shortcode', 'wpc-countdown-timer' ); ?></th>
379 <td>
380 <textarea class="wooct_shortcode" style="width: 100%; height: 120px" readonly><?php esc_html_e( 'Configure below options to build your shortcode :)', 'wpc-countdown-timer' ); ?></textarea>
381 <p class="description" style="color: #c9356e">
382 * This feature only available on Premium Version. Click
383 <a href="https://wpclever.net/downloads/wpc-countdown-timer?utm_source=pro&utm_medium=wooct&utm_campaign=wporg" target="_blank">here</a> to buy, just $29!
384 </p>
385 </td>
386 </tr>
387 <?php self::configure_form(); ?>
388 </table>
389 <?php } elseif ( $active_tab == 'premium' ) { ?>
390 <div class="wpclever_settings_page_content_text">
391 <p>
392 Get the Premium Version just $29!
393 <a href="https://wpclever.net/downloads/wpc-countdown-timer?utm_source=pro&utm_medium=wooct&utm_campaign=wporg" target="_blank">https://wpclever.net/downloads/wpc-countdown-timer</a>
394 </p>
395 <p><strong>Extra features for Premium Version:</strong></p>
396 <ul style="margin-bottom: 0">
397 <li>- Build your custom countdown timer to place everywhere you want by using shortcode builder.</li>
398 <li>- Configure countdown timer on a variation basis.</li>
399 <li>- Get the lifetime update & premium support.</li>
400 </ul>
401 </div>
402 <?php } ?>
403 </div>
404 </div>
405 <?php
406 }
407
408 function configure_form( $post_id = 0, $is_variation = false ) {
409 $active = get_post_meta( $post_id, 'wooct_active', true ) ?: 'no';
410 $style = get_post_meta( $post_id, 'wooct_style', true ) ?: apply_filters( 'wooct_default_style', '01' );
411 $time = get_post_meta( $post_id, 'wooct_time', true ) ?: 'custom';
412 $time_start = get_post_meta( $post_id, 'wooct_time_start', true ) ?: '';
413 $time_end = get_post_meta( $post_id, 'wooct_time_end', true ) ?: '';
414 $text_above = get_post_meta( $post_id, 'wooct_text_above', true ) ?: '';
415 $text_under = get_post_meta( $post_id, 'wooct_text_under', true ) ?: '';
416 $text_ended = get_post_meta( $post_id, 'wooct_text_ended', true ) ?: '';
417 $default_style = apply_filters( 'wooct_default_style', '01' );
418 $styles = apply_filters( 'wooct_styles', [
419 '01' => esc_html__( 'Style 01 (flat)', 'wpc-countdown-timer' ),
420 '02' => esc_html__( 'Style 02 (square)', 'wpc-countdown-timer' ),
421 '03' => esc_html__( 'Style 03 (rounded)', 'wpc-countdown-timer' ),
422 '04' => esc_html__( 'Style 04 (light flipper)', 'wpc-countdown-timer' ),
423 '05' => esc_html__( 'Style 05 (dark flipper)', 'wpc-countdown-timer' ),
424 '06' => esc_html__( 'Style 06 (rounded)', 'wpc-countdown-timer' ),
425 ] );
426
427 if ( empty( $style ) ) {
428 $style = $default_style;
429 }
430
431 if ( $is_variation ) {
432 $name = '_v[' . $post_id . ']';
433 $tr = '<p class="form-field form-row">';
434 $_tr = '</p>';
435 $th = '<label>';
436 $_th = '</label>';
437 $td = $_td = '';
438 } else {
439 $name = '';
440 $tr = '<tr>';
441 $_tr = '</tr>';
442 $th = '<th>';
443 $_th = '</th>';
444 $td = '<td>';
445 $_td = '</td>';
446 }
447
448 if ( $is_variation ) {
449 ?>
450 <p class="form-field form-row" style="color: #c9356e">
451 * This feature only available on Premium Version. Click
452 <a href="https://wpclever.net/downloads/wpc-countdown-timer?utm_source=pro&utm_medium=wooct&utm_campaign=wporg" target="_blank">here</a> to buy, just $29!
453 </p>
454 <?php
455 }
456
457 if ( $post_id ) {
458 echo $tr;
459 echo $th . esc_html__( 'Active', 'wpc-countdown-timer' ) . $_th;
460 echo $td;
461 echo '<select name="' . esc_attr( 'wooct_active' . $name ) . '" class="wooct_active">';
462 echo '<option value="yes" ' . selected( $active, 'yes', false ) . '>' . esc_html__( 'Yes', 'wpc-countdown-timer' ) . '</option>';
463 echo '<option value="no" ' . selected( $active, 'no', false ) . '>' . esc_html__( 'No', 'wpc-countdown-timer' ) . '</option>';
464 echo '</select>';
465 echo $_td;
466 echo $_tr;
467
468 echo $tr;
469 echo $th . esc_html__( 'Time', 'wpc-countdown-timer' ) . $_th;
470 echo $td;
471 echo '<select name="' . esc_attr( 'wooct_time' . $name ) . '" class="wooct_time">';
472 echo '<option value="custom" ' . selected( $time, 'custom', false ) . '>' . esc_html__( 'Custom', 'wpc-countdown-timer' ) . '</option>';
473 echo '<option value="sale" ' . selected( $time, 'sale', false ) . '>' . esc_html__( 'Sale price dates', 'wpc-countdown-timer' ) . '</option>';
474 echo '</select>';
475 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>';
476 echo $_td;
477 echo $_tr;
478 }
479
480 if ( $is_variation ) {
481 echo '<p class="form-field form-row wooct_show_if_custom">';
482 } else {
483 echo '<tr class="wooct_show_if_custom">';
484 }
485
486 echo $th . esc_html__( 'Start time', 'wpc-countdown-timer' ) . $_th;
487 echo $td;
488 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"/>';
489 echo $_td;
490 echo $_tr;
491
492 if ( $is_variation ) {
493 echo '<p class="form-field form-row wooct_show_if_custom">';
494 } else {
495 echo '<tr class="wooct_show_if_custom">';
496 }
497
498 echo $th . esc_html__( 'End time', 'wpc-countdown-timer' ) . $_th;
499 echo $td;
500 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"/>';
501 echo $_td;
502 echo $_tr;
503
504 echo $tr;
505 echo $th . esc_html__( 'Above text', 'wpc-countdown-timer' ) . $_th;
506 echo $td . '<input name="' . esc_attr( 'wooct_text_above' . $name ) . '" value="' . stripslashes( $text_above ) . '" class="wooct_text_above" type="text" style="width: 100%"/>' . $_td;
507 echo $_tr;
508
509 echo $tr;
510 echo $th . esc_html__( 'Under text', 'wpc-countdown-timer' ) . $_th;
511 echo $td . '<input name="' . esc_attr( 'wooct_text_under' . $name ) . '" value="' . stripslashes( $text_under ) . '" class="wooct_text_under" type="text" style="width: 100%"/>' . $_td;
512 echo $_tr;
513
514 echo $tr;
515 echo $th . esc_html__( 'Ended text', 'wpc-countdown-timer' ) . $_th;
516 echo $td . '<input name="' . esc_attr( 'wooct_text_ended' . $name ) . '" value="' . stripslashes( $text_ended ) . '" class="wooct_text_ended" type="text" style="width: 100%"/>' . $_td;
517 echo $_tr;
518
519 echo $tr;
520 echo $th . esc_html__( 'Style', 'wpc-countdown-timer' ) . $_th;
521 echo $td . '<select name="' . esc_attr( 'wooct_style' . $name ) . '" class="wooct_style">';
522
523 foreach ( $styles as $k => $s ) {
524 echo '<option value="' . esc_attr( $k ) . '" ' . selected( $style, $k, false ) . '>' . esc_html( $s ) . '</option>';
525 }
526
527 echo '</select>' . $_td;
528 echo $_tr;
529 }
530
531 function shortcode_product( $attrs ) {
532 $countdown = '';
533
534 $attrs = shortcode_atts( [
535 'id' => null
536 ], $attrs, 'wooct_product' );
537
538 if ( ! $attrs['id'] ) {
539 global $product;
540
541 if ( $product && $product->get_id() ) {
542 $attrs['id'] = $product->get_id();
543 }
544 }
545
546 if ( $attrs['id'] ) {
547 $active = apply_filters( 'wooct_active', get_post_meta( $attrs['id'], 'wooct_active', true ) ?: 'no', $attrs['id'] );
548
549 if ( $active === 'yes' ) {
550 $style = get_post_meta( $attrs['id'], 'wooct_style', true ) ?: apply_filters( 'wooct_default_style', '01' );
551 $text_above = get_post_meta( $attrs['id'], 'wooct_text_above', true ) ?: self::get_setting( 'text_above', '' );
552 $text_under = get_post_meta( $attrs['id'], 'wooct_text_under', true ) ?: self::get_setting( 'text_under', '' );
553 $text_ended = get_post_meta( $attrs['id'], 'wooct_text_ended', true ) ?: self::get_setting( 'text_ended', '' );
554 $time = get_post_meta( $attrs['id'], 'wooct_time', true ) ?: 'custom';
555
556 if ( $time === 'sale' ) {
557 $time_start = ( $date = get_post_meta( $attrs['id'], '_sale_price_dates_from', true ) ) ? date_i18n( 'm/d/Y H:i:s', $date ) : '';
558 $time_end = ( $date = get_post_meta( $attrs['id'], '_sale_price_dates_to', true ) ) ? date_i18n( 'm/d/Y H:i:s', $date ) : '';
559 } else {
560 $time_start = get_post_meta( $attrs['id'], 'wooct_time_start', true ) ?: '';
561 $time_end = get_post_meta( $attrs['id'], 'wooct_time_end', true ) ?: '';
562 }
563
564 $countdown = self::get_countdown( $style, $time_start, $time_end, $text_above, $text_under, $text_ended, $attrs['id'] );
565 }
566 }
567
568 return $countdown;
569 }
570
571 function show_countdown() {
572 echo do_shortcode( '[wooct_product]' );
573 }
574
575 function show_countdown_single() {
576 global $product;
577
578 echo '<div class="wooct-wrap-single" data-id="' . esc_attr( $product->get_id() ) . '">';
579 echo do_shortcode( '[wooct_product]' );
580 echo '</div>';
581 }
582
583 function enqueue_scripts() {
584 // moment
585 wp_enqueue_script( 'moment', WOOCT_URI . 'assets/libs/moment/moment.js', [ 'jquery' ], WOOCT_VERSION, true );
586 wp_enqueue_script( 'moment-timezone', WOOCT_URI . 'assets/libs/moment-timezone/moment-timezone-with-data.js', [ 'jquery' ], WOOCT_VERSION, true );
587
588 // jquery.countdown
589 if ( self::localization( 'zero_plural', 'yes' ) === 'yes' ) {
590 wp_enqueue_script( 'jquery.countdown', WOOCT_URI . 'assets/libs/jquery.countdown/jquery.countdown_zp.js', [ 'jquery' ], WOOCT_VERSION, true );
591 } else {
592 wp_enqueue_script( 'jquery.countdown', WOOCT_URI . 'assets/libs/jquery.countdown/jquery.countdown.js', [ 'jquery' ], WOOCT_VERSION, true );
593 }
594
595 // flipper
596 wp_enqueue_style( 'flipper', WOOCT_URI . 'assets/libs/flipper/style.css', [], WOOCT_VERSION );
597 wp_enqueue_script( 'flipper', WOOCT_URI . 'assets/libs/flipper/jquery.flipper-responsive.js', [ 'jquery' ], WOOCT_VERSION, true );
598
599 // wooct-frontend
600 wp_enqueue_style( 'wooct-frontend', WOOCT_URI . 'assets/css/frontend.css', [], WOOCT_VERSION );
601 wp_enqueue_script( 'wooct-frontend', WOOCT_URI . 'assets/js/frontend.js', [ 'jquery' ], WOOCT_VERSION, true );
602
603 // localization
604 $day = self::localization( 'day', esc_html__( 'Day', 'wpc-countdown-timer' ) );
605 $days = self::localization( 'days', esc_html__( 'Days', 'wpc-countdown-timer' ) );
606 $hour = self::localization( 'hour', esc_html__( 'Hour', 'wpc-countdown-timer' ) );
607 $hours = self::localization( 'hours', esc_html__( 'Hours', 'wpc-countdown-timer' ) );
608 $minute = self::localization( 'minute', esc_html__( 'Minute', 'wpc-countdown-timer' ) );
609 $minutes = self::localization( 'minutes', esc_html__( 'Minutes', 'wpc-countdown-timer' ) );
610 $second = self::localization( 'second', esc_html__( 'Second', 'wpc-countdown-timer' ) );
611 $seconds = self::localization( 'seconds', esc_html__( 'Seconds', 'wpc-countdown-timer' ) );
612
613 // format
614 $format_01 = '<span>%D %!D:' . $day . ',' . $days . ';</span> <span>%H</span>:<span>%M</span>:<span>%S</span>';
615 $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>';
616 $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>';
617
618 wp_localize_script( 'wooct-frontend', 'wooct_vars', [
619 'timezone' => get_option( 'timezone_string' ),
620 // default
621 'timer_format' => apply_filters( 'wooct_timer_format', $format_01 ),
622 // flat
623 'timer_format_01' => apply_filters( 'wooct_timer_format_01', $format_01 ),
624 // square
625 'timer_format_02' => apply_filters( 'wooct_timer_format_02', $format_02 ),
626 // rounded
627 'timer_format_03' => apply_filters( 'wooct_timer_format_03', $format_02 ),
628 'timer_format_06' => apply_filters( 'wooct_timer_format_06', $format_06 ),
629 ]
630 );
631 }
632
633 function admin_enqueue_scripts() {
634 // wpcdpk
635 wp_enqueue_style( 'wpcdpk', WOOCT_URI . 'assets/libs/wpcdpk/css/datepicker.css' );
636 wp_enqueue_script( 'wpcdpk', WOOCT_URI . 'assets/libs/wpcdpk/js/datepicker.js', [ 'jquery' ], WOOCT_VERSION, true );
637
638 // backend
639 wp_enqueue_style( 'wooct-backend', WOOCT_URI . 'assets/css/backend.css', [], WOOCT_VERSION );
640 wp_enqueue_script( 'wooct-backend', WOOCT_URI . 'assets/js/backend.js', [ 'jquery' ], WOOCT_VERSION, true );
641 wp_localize_script( 'wooct-backend', 'wooct_vars', [
642 'wooct_nonce' => wp_create_nonce( 'wooct_nonce' )
643 ]
644 );
645 }
646
647 function action_links( $links, $file ) {
648 static $plugin;
649
650 if ( ! isset( $plugin ) ) {
651 $plugin = plugin_basename( __FILE__ );
652 }
653
654 if ( $plugin === $file ) {
655 $settings = '<a href="' . admin_url( 'admin.php?page=wpclever-wooct&tab=settings' ) . '">' . esc_html__( 'Settings', 'wpc-countdown-timer' ) . '</a>';
656 $links['premium'] = '<a href="' . admin_url( 'admin.php?page=wpclever-wooct&tab=premium' ) . '">' . esc_html__( 'Premium Version', 'wpc-countdown-timer' ) . '</a>';
657 array_unshift( $links, $settings );
658 }
659
660 return (array) $links;
661 }
662
663 function row_meta( $links, $file ) {
664 static $plugin;
665
666 if ( ! isset( $plugin ) ) {
667 $plugin = plugin_basename( __FILE__ );
668 }
669
670 if ( $plugin === $file ) {
671 $row_meta = [
672 'support' => '<a href="' . esc_url( WOOCT_DISCUSSION ) . '" target="_blank">' . esc_html__( 'Community support', 'wpc-countdown-timer' ) . '</a>',
673 ];
674
675 return array_merge( $links, $row_meta );
676 }
677
678 return (array) $links;
679 }
680
681 function product_data_tabs( $tabs ) {
682 $tabs['wooct'] = [
683 'label' => esc_html__( 'Countdown', 'wpc-countdown-timer' ),
684 'target' => 'wooct_settings',
685 ];
686
687 return $tabs;
688 }
689
690 function product_data_panels() {
691 global $post;
692 ?>
693 <div id='wooct_settings' class='panel woocommerce_options_panel wooct_table'>
694 <div class="wooct_current_time">
695 <?php esc_html_e( 'Current time', 'wpc-countdown-timer' ); ?>
696 <code><?php echo current_time( 'm/d/Y' ); ?></code>
697 <code><?php echo current_time( 'h:i a' ); ?></code>
698 <a href="<?php echo admin_url( 'options-general.php' ); ?>" target="_blank"><?php esc_html_e( 'Date/time settings', 'wpc-countdown-timer' ); ?></a>
699 </div>
700 <div class="wooct_table">
701 <table class="wooct_time_form">
702 <?php self::configure_form( absint( $post->ID ) ); ?>
703 </table>
704 </div>
705 </div>
706 <?php
707 }
708
709 function process_product_meta( $post_id ) {
710 if ( isset( $_POST['wooct_active'] ) ) {
711 update_post_meta( $post_id, 'wooct_active', sanitize_text_field( $_POST['wooct_active'] ) );
712 } else {
713 delete_post_meta( $post_id, 'wooct_active' );
714 }
715
716 if ( isset( $_POST['wooct_time'] ) ) {
717 update_post_meta( $post_id, 'wooct_time', sanitize_text_field( $_POST['wooct_time'] ) );
718 } else {
719 delete_post_meta( $post_id, 'wooct_time' );
720 }
721
722 if ( isset( $_POST['wooct_time_start'] ) ) {
723 update_post_meta( $post_id, 'wooct_time_start', sanitize_text_field( $_POST['wooct_time_start'] ) );
724 } else {
725 delete_post_meta( $post_id, 'wooct_time_start' );
726 }
727
728 if ( isset( $_POST['wooct_time_end'] ) ) {
729 update_post_meta( $post_id, 'wooct_time_end', sanitize_text_field( $_POST['wooct_time_end'] ) );
730 } else {
731 delete_post_meta( $post_id, 'wooct_time_end' );
732 }
733
734 if ( isset( $_POST['wooct_text_above'] ) ) {
735 update_post_meta( $post_id, 'wooct_text_above', addslashes( $_POST['wooct_text_above'] ) );
736 } else {
737 delete_post_meta( $post_id, 'wooct_text_above' );
738 }
739
740 if ( isset( $_POST['wooct_text_under'] ) ) {
741 update_post_meta( $post_id, 'wooct_text_under', addslashes( $_POST['wooct_text_under'] ) );
742 } else {
743 delete_post_meta( $post_id, 'wooct_text_under' );
744 }
745
746 if ( isset( $_POST['wooct_text_ended'] ) ) {
747 update_post_meta( $post_id, 'wooct_text_ended', addslashes( $_POST['wooct_text_ended'] ) );
748 } else {
749 delete_post_meta( $post_id, 'wooct_text_ended' );
750 }
751
752 if ( isset( $_POST['wooct_style'] ) ) {
753 update_post_meta( $post_id, 'wooct_style', sanitize_text_field( $_POST['wooct_style'] ) );
754 } else {
755 delete_post_meta( $post_id, 'wooct_style' );
756 }
757 }
758
759 function variation_settings( $loop, $variation_data, $variation ) {
760 ?>
761 <div class="form-row form-row-full wooct-variation-settings">
762 <label><?php esc_html_e( 'WPC Countdown Timer', 'wpc-countdown-timer' ); ?></label>
763 <div class="wooct-variation-wrap wooct_time_form">
764 <?php self::configure_form( absint( $variation->ID ), true ); ?>
765 </div>
766 </div>
767 <?php
768 }
769
770 function save_variation_settings( $post_id ) {
771 if ( isset( $_POST['wooct_active_v'][ $post_id ] ) ) {
772 update_post_meta( $post_id, 'wooct_active', sanitize_text_field( $_POST['wooct_active_v'][ $post_id ] ) );
773 } else {
774 delete_post_meta( $post_id, 'wooct_active' );
775 }
776
777 if ( isset( $_POST['wooct_time_v'][ $post_id ] ) ) {
778 update_post_meta( $post_id, 'wooct_time', sanitize_text_field( $_POST['wooct_time_v'][ $post_id ] ) );
779 } else {
780 delete_post_meta( $post_id, 'wooct_time' );
781 }
782
783 if ( isset( $_POST['wooct_time_start_v'][ $post_id ] ) ) {
784 update_post_meta( $post_id, 'wooct_time_start', sanitize_text_field( $_POST['wooct_time_start_v'][ $post_id ] ) );
785 } else {
786 delete_post_meta( $post_id, 'wooct_time_start' );
787 }
788
789 if ( isset( $_POST['wooct_time_end_v'][ $post_id ] ) ) {
790 update_post_meta( $post_id, 'wooct_time_end', sanitize_text_field( $_POST['wooct_time_end_v'][ $post_id ] ) );
791 } else {
792 delete_post_meta( $post_id, 'wooct_time_end' );
793 }
794
795 if ( isset( $_POST['wooct_text_above_v'][ $post_id ] ) ) {
796 update_post_meta( $post_id, 'wooct_text_above', addslashes( $_POST['wooct_text_above_v'][ $post_id ] ) );
797 } else {
798 delete_post_meta( $post_id, 'wooct_text_above' );
799 }
800
801 if ( isset( $_POST['wooct_text_under_v'][ $post_id ] ) ) {
802 update_post_meta( $post_id, 'wooct_text_under', addslashes( $_POST['wooct_text_under_v'][ $post_id ] ) );
803 } else {
804 delete_post_meta( $post_id, 'wooct_text_under' );
805 }
806
807 if ( isset( $_POST['wooct_text_ended_v'][ $post_id ] ) ) {
808 update_post_meta( $post_id, 'wooct_text_ended', addslashes( $_POST['wooct_text_ended_v'][ $post_id ] ) );
809 } else {
810 delete_post_meta( $post_id, 'wooct_text_ended' );
811 }
812
813 if ( isset( $_POST['wooct_style_v'][ $post_id ] ) ) {
814 update_post_meta( $post_id, 'wooct_style', sanitize_text_field( $_POST['wooct_style_v'][ $post_id ] ) );
815 } else {
816 delete_post_meta( $post_id, 'wooct_style' );
817 }
818 }
819
820 function after_variations_table() {
821 global $product;
822
823 echo '<div class="wooct-wrap-variation" data-id="' . esc_attr( $product->get_id() ) . '"></div>';
824 }
825
826 function check_time_start( $start = '' ) {
827 if ( ! empty( $start ) ) {
828 if ( ! is_numeric( $start ) ) {
829 $start = strtotime( $start );
830 }
831
832 if ( current_time( 'timestamp' ) < $start ) {
833 return false;
834 }
835 }
836
837 return true;
838 }
839
840 function check_time_end( $end ) {
841 if ( ! empty( $end ) ) {
842 if ( ! is_numeric( $end ) ) {
843 $end = strtotime( $end );
844 }
845
846 if ( current_time( 'timestamp' ) < $end ) {
847 return true;
848 }
849 }
850
851 return false;
852 }
853
854 function post_class( $classes, $product ) {
855 if ( $product->is_type( 'variation' ) && $product->get_parent_id() ) {
856 $product_id = $product->get_parent_id();
857 } else {
858 $product_id = $product->get_id();
859 }
860
861 $active = get_post_meta( $product_id, 'wooct_active', true ) ?: 'no';
862 $time = get_post_meta( $product_id, 'wooct_time', true ) ?: '';
863
864 if ( $time === 'sale' ) {
865 $time_start = ( $date = get_post_meta( $product_id, '_sale_price_dates_from', true ) ) ? date_i18n( 'm/d/Y H:i:s', $date ) : '';
866 $time_end = ( $date = get_post_meta( $product_id, '_sale_price_dates_to', true ) ) ? date_i18n( 'm/d/Y H:i:s', $date ) : '';
867 } else {
868 $time_start = get_post_meta( $product_id, 'wooct_time_start', true ) ?: '';
869 $time_end = get_post_meta( $product_id, 'wooct_time_end', true ) ?: '';
870 }
871
872 if ( $active === 'yes' ) {
873 $classes[] = 'wooct-active';
874 }
875
876 if ( ! self::check_time_end( $time_end ) ) {
877 $classes[] = 'wooct-ended';
878 } elseif ( self::check_time_start( $time_start ) ) {
879 $classes[] = 'wooct-running';
880 }
881
882 return $classes;
883 }
884
885 function get_countdown( $style, $time_start, $time_end, $text_above, $text_under, $text_ended, $product_id = 0 ) {
886 $countdown = '';
887 $style = apply_filters( 'wooct_style', $style, $product_id );
888 $time_start = apply_filters( 'wooct_time_start', $time_start, $product_id );
889 $time_end = apply_filters( 'wooct_time_end', $time_end, $product_id );
890 $text_above = apply_filters( 'wooct_text_above', $text_above, $product_id );
891 $text_under = apply_filters( 'wooct_text_under', $text_under, $product_id );
892 $text_ended = apply_filters( 'wooct_text_ended', $text_ended, $product_id );
893
894 if ( is_numeric( $time_start ) ) {
895 $time_start = date_i18n( 'm/d/Y H:i:s', $time_start );
896 }
897
898 if ( is_numeric( $time_end ) ) {
899 $time_end = date_i18n( 'm/d/Y H:i:s', $time_end );
900 }
901
902 if ( ! empty( $time_end ) && self::check_time_start( $time_start ) ) {
903 if ( ! self::check_time_end( $time_end ) ) {
904 if ( ! empty( $text_ended ) ) {
905 $class = 'wooct-countdown wooct-ended wooct-style-' . esc_attr( $style );
906 $countdown .= '<div class="' . esc_attr( apply_filters( 'wooct_class_ended', $class ) ) . '"><div class="wooct-text-ended">' . stripslashes( $text_ended ) . '</div></div>';
907 }
908 } else {
909 $class = 'wooct-countdown wooct-running wooct-style-' . esc_attr( $style ) . ' ' . ( $style === '04' || $style === '05' ? 'wooct-flipper' : '' );
910 $countdown .= '<div class="' . esc_attr( apply_filters( 'wooct_class', $class ) ) . '" data-style="' . esc_attr( $style ) . '" data-timer="' . esc_attr( $time_end ) . '" data-ended="' . htmlentities( stripslashes( $text_ended ) ) . '">';
911
912 if ( ! empty( $text_above ) ) {
913 $countdown .= '<div class="wooct-text-above">' . stripslashes( $text_above ) . '</div>';
914 }
915
916 if ( $style === '04' || $style === '05' ) {
917 // flipper
918 $days = self::localization( 'days', esc_html__( 'Days', 'wpc-countdown-timer' ) );
919 $hours = self::localization( 'hours', esc_html__( 'Hours', 'wpc-countdown-timer' ) );
920 $minutes = self::localization( 'minutes', esc_html__( 'Minutes', 'wpc-countdown-timer' ) );
921 $seconds = self::localization( 'seconds', esc_html__( 'Seconds', 'wpc-countdown-timer' ) );
922 $template = apply_filters( 'wooct_flipper_template', 'dd|HH|ii|ss' );
923 $labels = apply_filters( 'wooct_flipper_labels', $days . '|' . $hours . '|' . $minutes . '|' . $seconds );
924 $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>';
925 } else {
926 $countdown .= '<div class="wooct-timer">' . $time_end . '</div>';
927 }
928
929 if ( ! empty( $text_under ) ) {
930 $countdown .= '<div class="wooct-text-under">' . stripslashes( $text_under ) . '</div>';
931 }
932
933 $countdown .= '</div>';
934 }
935 }
936
937 return apply_filters( 'wooct_countdown', $countdown, $style, $time_start, $time_end, $text_above, $text_under, $text_ended, $product_id );
938 }
939
940 function product_columns( $columns ) {
941 $columns['wooct'] = esc_html__( 'Countdown', 'wpc-countdown-timer' );
942
943 return $columns;
944 }
945
946 function product_custom_column( $column, $postid ) {
947 if ( $column === 'wooct' ) {
948 $active = get_post_meta( $postid, 'wooct_active', true ) ?: 'no';
949 $time_start = get_post_meta( $postid, 'wooct_time_start', true ) ?: '';
950 $time_end = get_post_meta( $postid, 'wooct_time_end', true ) ?: '';
951
952 if ( ( $active === 'yes' ) && ! empty( $time_end ) ) {
953 if ( self::check_time_start( $time_start ) && self::check_time_end( $time_end ) ) {
954 echo '<span class="wooct-icon running"><span class="dashicons dashicons-clock"></span></span>';
955 } else {
956 echo '<span class="wooct-icon"><span class="dashicons dashicons-clock"></span></span>';
957 }
958 }
959 }
960 }
961
962 function duplicate_variation( $old_variation_id, $new_variation_id ) {
963 if ( $active = get_post_meta( $old_variation_id, 'wooct_active', true ) ) {
964 update_post_meta( $new_variation_id, 'wooct_active', $active );
965 }
966
967 if ( $time = get_post_meta( $old_variation_id, 'wooct_time', true ) ) {
968 update_post_meta( $new_variation_id, 'wooct_time', $time );
969 }
970
971 if ( $time_start = get_post_meta( $old_variation_id, 'wooct_time_start', true ) ) {
972 update_post_meta( $new_variation_id, 'wooct_time_start', $time_start );
973 }
974
975 if ( $time_end = get_post_meta( $old_variation_id, 'wooct_time_end', true ) ) {
976 update_post_meta( $new_variation_id, 'wooct_time_end', $time_end );
977 }
978
979 if ( $text_above = get_post_meta( $old_variation_id, 'wooct_text_above', true ) ) {
980 update_post_meta( $new_variation_id, 'wooct_text_above', $text_above );
981 }
982
983 if ( $text_under = get_post_meta( $old_variation_id, 'wooct_text_under', true ) ) {
984 update_post_meta( $new_variation_id, 'wooct_text_under', $text_under );
985 }
986
987 if ( $text_ended = get_post_meta( $old_variation_id, 'wooct_text_ended', true ) ) {
988 update_post_meta( $new_variation_id, 'wooct_text_ended', $text_ended );
989 }
990
991 if ( $style = get_post_meta( $old_variation_id, 'wooct_style', true ) ) {
992 update_post_meta( $new_variation_id, 'wooct_style', $style );
993 }
994 }
995
996 function bulk_update_variation( $variation_id, $fields ) {
997 if ( ! empty( $fields['wooct_active_v'] ) && ( $fields['wooct_active_v'] !== 'wpcvb_no_change' ) ) {
998 update_post_meta( $variation_id, 'wooct_active', sanitize_text_field( $fields['wooct_active_v'] ) );
999 }
1000
1001 if ( ! empty( $fields['wooct_time_v'] ) && ( $fields['wooct_time_v'] !== 'wpcvb_no_change' ) ) {
1002 update_post_meta( $variation_id, 'wooct_time', sanitize_text_field( $fields['wooct_time_v'] ) );
1003 }
1004
1005 if ( ! empty( $fields['wooct_time_start_v'] ) ) {
1006 update_post_meta( $variation_id, 'wooct_time_start', sanitize_text_field( $fields['wooct_time_start_v'] ) );
1007 }
1008
1009 if ( ! empty( $fields['wooct_time_end_v'] ) ) {
1010 update_post_meta( $variation_id, 'wooct_time_end', sanitize_text_field( $fields['wooct_time_end_v'] ) );
1011 }
1012
1013 if ( ! empty( $fields['wooct_text_above_v'] ) ) {
1014 update_post_meta( $variation_id, 'wooct_text_above', sanitize_text_field( $fields['wooct_text_above_v'] ) );
1015 }
1016
1017 if ( ! empty( $fields['wooct_text_under_v'] ) ) {
1018 update_post_meta( $variation_id, 'wooct_text_under', sanitize_text_field( $fields['wooct_text_under_v'] ) );
1019 }
1020
1021 if ( ! empty( $fields['wooct_text_ended_v'] ) ) {
1022 update_post_meta( $variation_id, 'wooct_text_ended', sanitize_text_field( $fields['wooct_text_ended_v'] ) );
1023 }
1024
1025 if ( ! empty( $fields['wooct_style_v'] ) && ( $fields['wooct_style_v'] !== 'wpcvb_no_change' ) ) {
1026 update_post_meta( $variation_id, 'wooct_style', sanitize_text_field( $fields['wooct_style_v'] ) );
1027 }
1028 }
1029
1030 public static function get_settings() {
1031 return apply_filters( 'wooct_get_settings', self::$settings );
1032 }
1033
1034 public static function get_setting( $name, $default = false ) {
1035 if ( ! empty( self::$settings ) && isset( self::$settings[ $name ] ) ) {
1036 $setting = self::$settings[ $name ];
1037 } else {
1038 $setting = get_option( 'wooct_' . $name, $default );
1039 }
1040
1041 return apply_filters( 'wooct_get_setting', $setting, $name, $default );
1042 }
1043
1044 public static function localization( $key = '', $default = '' ) {
1045 if ( ! empty( $key ) && ! empty( self::$localization[ $key ] ) ) {
1046 $str = self::$localization[ $key ];
1047 } else {
1048 $str = get_option( 'wooct_localization_' . $key );
1049
1050 if ( empty( $str ) ) {
1051 $str = $default;
1052 }
1053 }
1054
1055 return apply_filters( 'wooct_localization_' . $key, $str );
1056 }
1057 }
1058
1059 return WPCleverWooct::instance();
1060 }
1061 }
1062 }
1063
1064 if ( ! function_exists( 'wooct_notice_wc' ) ) {
1065 function wooct_notice_wc() {
1066 ?>
1067 <div class="error">
1068 <p><strong>WPC Countdown Timer</strong> require WooCommerce version 3.0 or greater.</p>
1069 </div>
1070 <?php
1071 }
1072 }
1073