PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
← All changes | inc/modules/countdown-timer/class-countdown-timer.php +310 -225 1.62.3.2 View file →
@@ -1,225 +1,310 @@
1 -<?php
2 -
3 -/**
4 - * Countdown timer.
5 - *
6 - * @package Merchant
7 - */
8 -
9 -if ( ! defined( 'ABSPATH' ) ) {
10 - exit; // Exit if accessed directly
11 -}
12 -
13 -/**
14 - * Countdown timer class.
15 - *
16 - */
17 -class Merchant_Countdown_Timer extends Merchant_Add_Module {
18 -
19 - /**
20 - * Module ID.
21 - *
22 - */
23 - const MODULE_ID = 'countdown-timer';
24 -
25 - /**
26 - * Module template path.
27 - */
28 - const MODULE_TEMPLATES = 'modules/' . self::MODULE_ID;
29 -
30 - /**
31 - * Is module preview.
32 - *
33 - */
34 - public static $is_module_preview = false;
35 -
36 - /**
37 - * Constructor.
38 - */
39 - public function __construct() {
40 - // Module id.
41 - $this->module_id = self::MODULE_ID;
42 -
43 - // WooCommerce only.
44 - $this->wc_only = true;
45 -
46 - // Parent construct.
47 - parent::__construct();
48 -
49 - // Module section.
50 - $this->module_section = 'convert-more';
51 -
52 - // Module default settings.
53 - $this->module_default_settings = array(
54 - 'discount_products_only' => true,
55 - 'sale_ending_text' => esc_html__( 'Sale ends in', 'merchant' ),
56 - 'end_date' => 'evergreen',
57 - 'cool_off_period' => 15,
58 - 'min_expiration_deadline' => 2,
59 - 'max_expiration_deadline' => 26,
60 - 'sale_ending_alignment' => 'left',
61 - );
62 -
63 - // Mount preview url.
64 - $preview_url = site_url( '/' );
65 -
66 - if ( function_exists( 'wc_get_products' ) ) {
67 - $products = wc_get_products( array( 'limit' => 1 ) );
68 -
69 - if ( ! empty( $products ) && ! empty( $products[0] ) ) {
70 - $preview_url = get_permalink( $products[0]->get_id() );
71 - }
72 - }
73 -
74 - // Module data.
75 - $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
76 - $this->module_data['preview_url'] = $preview_url;
77 -
78 - // Module options path.
79 - $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
80 -
81 - // Is module preview page.
82 - if ( is_admin() && parent::is_module_settings_page() ) {
83 - self::$is_module_preview = true;
84 -
85 - // Enqueue admin styles.
86 - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
87 -
88 - // Enqueue admin scripts.
89 - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
90 -
91 - // Admin preview box.
92 - add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
93 -
94 - // Custom CSS.
95 - // The custom CSS should be added here as well due to ensure preview box works properly.
96 - add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
97 - }
98 - }
99 -
100 - /**
101 - * Admin enqueue CSS.
102 - *
103 - * @return void
104 - */
105 - public function admin_enqueue_css() {
106 - if ( $this->is_module_settings_page() ) {
107 - wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/countdown-timer.min.css', [], MERCHANT_VERSION );
108 - wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
109 - }
110 - }
111 -
112 - /**
113 - * Admin Enqueue scripts.
114 - *
115 - * @return void
116 - */
117 - public function admin_enqueue_scripts() {
118 - wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/countdown-timer.min.js', array(), MERCHANT_VERSION, true );
119 - wp_enqueue_script( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js', array(), MERCHANT_VERSION, true );
120 - }
121 -
122 - /**
123 - * Render admin preview
124 - *
125 - * @param Merchant_Admin_Preview $preview
126 - * @param string $module
127 - *
128 - * @return Merchant_Admin_Preview
129 - */
130 - public function render_admin_preview( $preview, $module ) {
131 - if ( self::MODULE_ID === $module ) {
132 - ob_start();
133 - self::admin_preview_content();
134 - $content = ob_get_clean();
135 -
136 - // HTML.
137 - $preview->set_html( $content );
138 -
139 - // Sale Ending Color
140 - $preview->set_css( 'sale_ending_color', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' );
141 -
142 - // Digits Color
143 - $preview->set_css( 'digits_color', '.merchant-countdown-timer-countdown', '--merchant-digits-color' );
144 -
145 - // Icon Color.
146 - $preview->set_css( 'icon_color', '.merchant-countdown-timer svg', '--merchant-icon-color' );
147 -
148 - // Sale Ending Text.
149 - $preview->set_text( 'sale_ending_text', '.merchant-countdown-timer-text' );
150 - }
151 -
152 - return $preview;
153 - }
154 -
155 - /**
156 - * Admin preview content.
157 - *
158 - * @return void
159 - */
160 - public function admin_preview_content() {
161 - $settings = $this->get_module_settings();
162 - ?>
163 -
164 - <div class="mrc-preview-single-product-elements">
165 - <div class="mrc-preview-left-column">
166 - <div class="mrc-preview-product-image-wrapper">
167 - <div class="mrc-preview-product-image"></div>
168 - <div class="mrc-preview-product-image-thumbs">
169 - <div class="mrc-preview-product-image-thumb"></div>
170 - <div class="mrc-preview-product-image-thumb"></div>
171 - <div class="mrc-preview-product-image-thumb"></div>
172 - </div>
173 - </div>
174 - </div>
175 - <div class="mrc-preview-right-column">
176 - <div class="mrc-preview-text-placeholder"></div>
177 - <div class="mrc-preview-text-placeholder mrc-mw-70"></div>
178 - <div class="mrc-preview-text-placeholder mrc-mw-30"></div>
179 - <div class="mrc-preview-text-placeholder mrc-mw-40"></div>
180 - <?php echo wp_kses( merchant_get_template_part( self::MODULE_TEMPLATES, 'single-product', $settings, true ), merchant_kses_allowed_tags() ); ?>
181 - <div class="mrc-preview-addtocart-placeholder"></div>
182 - </div>
183 - </div>
184 -
185 - <?php
186 - }
187 -
188 - /**
189 - * Custom CSS.
190 - *
191 - * @return string
192 - */
193 - public function get_module_custom_css() {
194 - $css = '';
195 -
196 - // Sale Ending Color.
197 - $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'sale_ending_color', '#626262', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' );
198 -
199 - // Digits Color.
200 - $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_color', '#444444', '.merchant-countdown-timer-countdown', '--merchant-digits-color' );
201 -
202 - // Icon Color.
203 - $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon_color', '#626262', '.merchant-countdown-timer svg', '--merchant-icon-color' );
204 -
205 - return $css;
206 - }
207 -
208 - /**
209 - * Admin custom CSS.
210 - *
211 - * @param string $css The custom CSS.
212 - *
213 - * @return string $css The custom CSS.
214 - */
215 - public function admin_custom_css( $css ) {
216 - $css .= $this->get_module_custom_css();
217 -
218 - return $css;
219 - }
220 -}
221 -
222 -// Initialize the module.
223 -add_action( 'init', function () {
224 - Merchant_Modules::create_module( new Merchant_Countdown_Timer() );
225 -} );
1 +<?php
2 +
3 +/**
4 + * Countdown timer.
5 + *
6 + * @package Merchant
7 + */
8 +
9 +if ( ! defined( 'ABSPATH' ) ) {
10 + exit; // Exit if accessed directly
11 +}
12 +
13 +/**
14 + * Countdown timer class.
15 + *
16 + */
17 +class Merchant_Countdown_Timer extends Merchant_Add_Module {
18 +
19 + /**
20 + * Module ID.
21 + *
22 + */
23 + const MODULE_ID = 'countdown-timer';
24 +
25 + /**
26 + * Module template path.
27 + */
28 + const MODULE_TEMPLATES = 'modules/' . self::MODULE_ID;
29 +
30 + /**
31 + * Is module preview.
32 + *
33 + */
34 + public static $is_module_preview = false;
35 +
36 + /**
37 + * Initialize the module's option group definitions.
38 + *
39 + * @return array<int, array<string, mixed>> Array of option group arrays.
40 + */
41 + protected function init_option_groups() {
42 + return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
43 + }
44 +
45 + /**
46 + * Constructor.
47 + */
48 + public function __construct() {
49 + // Module id.
50 + $this->module_id = self::MODULE_ID;
51 +
52 + // WooCommerce only.
53 + $this->wc_only = true;
54 +
55 + // Parent construct.
56 + parent::__construct();
57 +
58 + // Module section.
59 + $this->module_section = 'convert-more';
60 +
61 + // Module default settings.
62 + $this->module_default_settings = array(
63 + 'discount_products_only' => true,
64 + 'sale_ending_text' => esc_html__( 'Sale ends in', 'merchant' ),
65 + 'end_date' => 'evergreen',
66 + 'cool_off_period' => 15,
67 + 'min_expiration_deadline' => 2,
68 + 'max_expiration_deadline' => 26,
69 + 'sale_ending_alignment' => 'left',
70 + );
71 +
72 + // Module data.
73 + $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
74 +
75 + // AI prompt examples.
76 + $this->ai_examples = array(
77 + 'blurb' => esc_html__( 'See what AI can do for your countdown timer, from setting when the sale ends to restyling how the timer looks.', 'merchant' ),
78 + 'prompts' => array(
79 + esc_html__( 'Explore the abilities WPVibe gives you access to, then switch the countdown timer to sale-price dates and set it to end at midnight on November 30 for our Black Friday sale', 'merchant' ),
80 + esc_html__( 'Check what abilities you have available through WPVibe, then switch the countdown timer to an evergreen timer that gives each visitor a fresh 24-hour deadline', 'merchant' ),
81 + esc_html__( "Look at your available WPVibe abilities, then change the sale ending message above the countdown timer to 'Black Friday ends in' and center it", 'merchant' ),
82 + esc_html__( 'See what abilities WPVibe exposes, then switch the countdown timer to the Circles layout with red digits', 'merchant' ),
83 + ),
84 + );
85 +
86 + // Module options path.
87 + $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
88 +
89 + // Is module preview page.
90 + if ( is_admin() && parent::is_module_settings_page() ) {
91 + self::$is_module_preview = true;
92 +
93 + // Enqueue admin styles.
94 + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
95 +
96 + // Enqueue admin scripts.
97 + add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
98 +
99 + // Localize Script.
100 + add_filter( 'merchant_admin_localize_script', array( $this, 'localize_script' ) );
101 +
102 + // Admin preview box.
103 + add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
104 +
105 + // Custom CSS.
106 + // The custom CSS should be added here as well due to ensure preview box works properly.
107 + add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
108 + }
109 +
110 + if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
111 + // Init translations.
112 + $this->init_translations();
113 + }
114 + }
115 +
116 + /**
117 + * Init translations.
118 + *
119 + * @return void
120 + */
121 + public function init_translations() {
122 + $settings = $this->get_module_settings();
123 + if ( ! empty( $settings['sale_ending_text'] ) ) {
124 + Merchant_Translator::register_string( $settings['sale_ending_text'], esc_html__( 'Countdown Timer: Sale ending message', 'merchant' ) );
125 + }
126 + }
127 +
128 + /**
129 + * Admin enqueue CSS.
130 + *
131 + * @return void
132 + */
133 + public function admin_enqueue_css() {
134 + if ( $this->is_module_settings_page() ) {
135 + wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/countdown-timer.min.css', array(), MERCHANT_VERSION );
136 + wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
137 + }
138 + }
139 +
140 + /**
141 + * Admin Enqueue scripts.
142 + *
143 + * @return void
144 + */
145 + public function admin_enqueue_scripts() {
146 + wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/countdown-timer.min.js', array(), MERCHANT_VERSION, true );
147 + wp_enqueue_script( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js', array(), MERCHANT_VERSION, true );
148 + }
149 +
150 + /**
151 + * Localize Script.
152 + */
153 + public function localize_script( $data ) {
154 + $data['is_admin'] = is_admin();
155 +
156 + return $data;
157 + }
158 +
159 + /**
160 + * Render admin preview
161 + *
162 + * @param Merchant_Admin_Preview $preview
163 + * @param string $module
164 + *
165 + * @return Merchant_Admin_Preview
166 + */
167 + public function render_admin_preview( $preview, $module ) {
168 + if ( self::MODULE_ID === $module ) {
169 + ob_start();
170 + self::admin_preview_content();
171 + $content = ob_get_clean();
172 +
173 + // HTML.
174 + $preview->set_html( $content );
175 +
176 + // Font size
177 + $preview->set_css( 'digits_font_size', '.merchant-countdown-timer-countdown', '--merchant-digits-font-size', 'px' );
178 + $preview->set_css( 'labels_font_size', '.merchant-countdown-timer-countdown', '--merchant-labels-font-size', 'px' );
179 +
180 + // Sale Ending Color
181 + $preview->set_css( 'sale_ending_color', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' );
182 +
183 + // Digits Color
184 + $preview->set_css( 'digits_color', '.merchant-countdown-timer-countdown', '--merchant-digits-color' );
185 +
186 + // Digits Background Color
187 + $preview->set_css( 'digits_background', '.merchant-countdown-timer-countdown', '--merchant-digits-background' );
188 +
189 + // Progress Color
190 + $preview->set_css( 'progress_color', '.merchant-countdown-timer-countdown', '--merchant-progress-color' );
191 +
192 + // Labels Color
193 + $preview->set_css( 'labels_color', '.merchant-countdown-timer-countdown', '--merchant-labels-color' );
194 +
195 + // Border Color
196 + $preview->set_css( 'digits_border', '.merchant-countdown-timer-countdown', '--merchant-digits-border' );
197 +
198 + // Digits width & height
199 + $preview->set_css( 'digits_width', '.merchant-countdown-timer-countdown', '--merchant-digits-width', 'px' );
200 + $preview->set_css( 'digits_height', '.merchant-countdown-timer-countdown', '--merchant-digits-height', 'px' );
201 +
202 + // Icon Color.
203 + $preview->set_css( 'icon_color', '.merchant-countdown-timer svg', '--merchant-icon-color' );
204 +
205 + // Sale Ending Text.
206 + $preview->set_text( 'sale_ending_text', '.merchant-countdown-timer-text' );
207 + }
208 +
209 + return $preview;
210 + }
211 +
212 + /**
213 + * Admin preview content.
214 + *
215 + * @return void
216 + */
217 + public function admin_preview_content() {
218 + $settings = $this->get_module_settings();
219 + ?>
220 +
221 + <div class="mrc-preview-single-product-elements">
222 + <div class="mrc-preview-left-column">
223 + <div class="mrc-preview-product-image-wrapper">
224 + <div class="mrc-preview-product-image"></div>
225 + </div>
226 + </div>
227 + <div class="mrc-preview-right-column">
228 + <h3 style="margin-top: 0;"><?php echo esc_html__( 'Your Product Name', 'merchant' ); ?></h3>
229 + <div class="mrc-preview-rating">
230 + <div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated 3.00 out of 5">
231 + <span style="width: 80%"></span>
232 + </div>
233 + <span style="color: #969696;"><?php echo esc_html__( 'reviews', 'merchant' ); ?></span>
234 + </div>
235 + <h3><?php echo esc_html__( '$49', 'merchant' ); ?></h3>
236 + <p><?php echo esc_html__( "An amazing product people can't refuse. What’s the next moment of value-realization when using your product? Tell the biggest use case. Briefly expand your product benefits on how this will help customers.", 'merchant' ); ?></p>
237 + <?php echo wp_kses( merchant_get_template_part( self::MODULE_TEMPLATES, 'single-product', $settings, true ), merchant_kses_allowed_tags() ); ?>
238 +
239 + <div class="merchant-preview-add-to-cart-inner">
240 + <div class="merchant-preview-qty">
241 + <button><?php echo esc_html( '+' ); ?></button>
242 + <input type="text" value="<?php echo esc_attr( '1' ); ?>">
243 + <button><?php echo esc_html( '-' ); ?></button>
244 + </div>
245 + <div class="merchant-preview-add-to-cart"><?php echo esc_html__( 'Add to cart', 'merchant' ); ?></div>
246 + </div>
247 + </div>
248 + </div>
249 +
250 + <?php
251 + }
252 +
253 + /**
254 + * Custom CSS.
255 + *
256 + * @return string
257 + */
258 + public function get_module_custom_css() {
259 + $css = '';
260 +
261 + // Font sizes
262 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_font_size', 16, '.merchant-countdown-timer-countdown', '--merchant-digits-font-size', 'px' );
263 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'labels_font_size', 16, '.merchant-countdown-timer-countdown', '--merchant-labels-font-size', 'px' );
264 +
265 + // Sale Ending Color.
266 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'sale_ending_color', '#626262', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' );
267 +
268 + // Digits Color.
269 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_color', '#444444', '.merchant-countdown-timer-countdown', '--merchant-digits-color' );
270 +
271 + // Digits Background Color.
272 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_background', '#fff', '.merchant-countdown-timer-countdown', '--merchant-digits-background' );
273 +
274 + // Progress Color.
275 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'progress_color', '#3858E9', 'body', '--merchant-progress-color' );
276 +
277 + // Labels Color.
278 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'labels_color', '#444444', '.merchant-countdown-timer-countdown', '--merchant-labels-color' );
279 +
280 + // Border Color.
281 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_border', '#444444', '.merchant-countdown-timer-countdown', '--merchant-digits-border' );
282 +
283 + // Digits width & height
284 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_width', 80, '.merchant-countdown-timer-countdown', '--merchant-digits-width', 'px' );
285 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_height', 80, '.merchant-countdown-timer-countdown', '--merchant-digits-height', 'px' );
286 +
287 + // Icon Color.
288 + $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon_color', '#626262', '.merchant-countdown-timer svg', '--merchant-icon-color' );
289 +
290 + return $css;
291 + }
292 +
293 + /**
294 + * Admin custom CSS.
295 + *
296 + * @param string $css The custom CSS.
297 + *
298 + * @return string $css The custom CSS.
299 + */
300 + public function admin_custom_css( $css ) {
301 + $css .= $this->get_module_custom_css();
302 +
303 + return $css;
304 + }
305 +}
306 +
307 +// Initialize the module.
308 +add_action( 'init', function () {
309 + Merchant_Modules::create_module( new Merchant_Countdown_Timer() );
310 +} );