PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.2.7
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.2.7
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
merchant / inc / modules / countdown-timer / class-countdown-timer.php

class-countdown-timer.php in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.2.7, at inc/modules/countdown-timer/class-countdown-timer.php

290 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // Module data.
64 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
65
66 // Module options path.
67 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
68
69 // Is module preview page.
70 if ( is_admin() && parent::is_module_settings_page() ) {
71 self::$is_module_preview = true;
72
73 // Enqueue admin styles.
74 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
75
76 // Enqueue admin scripts.
77 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
78
79 // Localize Script.
80 add_filter( 'merchant_admin_localize_script', array( $this, 'localize_script' ) );
81
82 // Admin preview box.
83 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
84
85 // Custom CSS.
86 // The custom CSS should be added here as well due to ensure preview box works properly.
87 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
88 }
89
90 if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
91 // Init translations.
92 $this->init_translations();
93 }
94 }
95
96 /**
97 * Init translations.
98 *
99 * @return void
100 */
101 public function init_translations() {
102 $settings = $this->get_module_settings();
103 if ( ! empty( $settings['sale_ending_text'] ) ) {
104 Merchant_Translator::register_string( $settings['sale_ending_text'], esc_html__( 'Countdown Timer: Sale ending message', 'merchant' ) );
105 }
106 }
107
108 /**
109 * Admin enqueue CSS.
110 *
111 * @return void
112 */
113 public function admin_enqueue_css() {
114 if ( $this->is_module_settings_page() ) {
115 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/countdown-timer.min.css', array(), MERCHANT_VERSION );
116 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
117 }
118 }
119
120 /**
121 * Admin Enqueue scripts.
122 *
123 * @return void
124 */
125 public function admin_enqueue_scripts() {
126 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/countdown-timer.min.js', array(), MERCHANT_VERSION, true );
127 wp_enqueue_script( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js', array(), MERCHANT_VERSION, true );
128 }
129
130 /**
131 * Localize Script.
132 */
133 public function localize_script( $data ) {
134 $data['is_admin'] = is_admin();
135
136 return $data;
137 }
138
139 /**
140 * Render admin preview
141 *
142 * @param Merchant_Admin_Preview $preview
143 * @param string $module
144 *
145 * @return Merchant_Admin_Preview
146 */
147 public function render_admin_preview( $preview, $module ) {
148 if ( self::MODULE_ID === $module ) {
149 ob_start();
150 self::admin_preview_content();
151 $content = ob_get_clean();
152
153 // HTML.
154 $preview->set_html( $content );
155
156 // Font size
157 $preview->set_css( 'digits_font_size', '.merchant-countdown-timer-countdown', '--merchant-digits-font-size', 'px' );
158 $preview->set_css( 'labels_font_size', '.merchant-countdown-timer-countdown', '--merchant-labels-font-size', 'px' );
159
160 // Sale Ending Color
161 $preview->set_css( 'sale_ending_color', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' );
162
163 // Digits Color
164 $preview->set_css( 'digits_color', '.merchant-countdown-timer-countdown', '--merchant-digits-color' );
165
166 // Digits Background Color
167 $preview->set_css( 'digits_background', '.merchant-countdown-timer-countdown', '--merchant-digits-background' );
168
169 // Progress Color
170 $preview->set_css( 'progress_color', '.merchant-countdown-timer-countdown', '--merchant-progress-color' );
171
172 // Labels Color
173 $preview->set_css( 'labels_color', '.merchant-countdown-timer-countdown', '--merchant-labels-color' );
174
175 // Border Color
176 $preview->set_css( 'digits_border', '.merchant-countdown-timer-countdown', '--merchant-digits-border' );
177
178 // Digits width & height
179 $preview->set_css( 'digits_width', '.merchant-countdown-timer-countdown', '--merchant-digits-width', 'px' );
180 $preview->set_css( 'digits_height', '.merchant-countdown-timer-countdown', '--merchant-digits-height', 'px' );
181
182 // Icon Color.
183 $preview->set_css( 'icon_color', '.merchant-countdown-timer svg', '--merchant-icon-color' );
184
185 // Sale Ending Text.
186 $preview->set_text( 'sale_ending_text', '.merchant-countdown-timer-text' );
187 }
188
189 return $preview;
190 }
191
192 /**
193 * Admin preview content.
194 *
195 * @return void
196 */
197 public function admin_preview_content() {
198 $settings = $this->get_module_settings();
199 ?>
200
201 <div class="mrc-preview-single-product-elements">
202 <div class="mrc-preview-left-column">
203 <div class="mrc-preview-product-image-wrapper">
204 <div class="mrc-preview-product-image"></div>
205 </div>
206 </div>
207 <div class="mrc-preview-right-column">
208 <h3 style="margin-top: 0;"><?php echo esc_html__( 'Your Product Name', 'merchant' ); ?></h3>
209 <div class="mrc-preview-rating">
210 <div class="star-rating merchant-star-rating-style2" role="img" aria-label="Rated 3.00 out of 5">
211 <span style="width: 80%"></span>
212 </div>
213 <span style="color: #969696;"><?php echo esc_html__( 'reviews', 'merchant' ); ?></span>
214 </div>
215 <h3><?php echo esc_html__( '$49', 'merchant' ); ?></h3>
216 <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>
217 <?php echo wp_kses( merchant_get_template_part( self::MODULE_TEMPLATES, 'single-product', $settings, true ), merchant_kses_allowed_tags() ); ?>
218
219 <div class="merchant-preview-add-to-cart-inner">
220 <div class="merchant-preview-qty">
221 <button><?php echo esc_html( '+' ); ?></button>
222 <input type="text" value="<?php echo esc_attr( '1' ); ?>">
223 <button><?php echo esc_html( '-' ); ?></button>
224 </div>
225 <div class="merchant-preview-add-to-cart"><?php echo esc_html__( 'Add to cart', 'merchant' ); ?></div>
226 </div>
227 </div>
228 </div>
229
230 <?php
231 }
232
233 /**
234 * Custom CSS.
235 *
236 * @return string
237 */
238 public function get_module_custom_css() {
239 $css = '';
240
241 // Font sizes
242 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_font_size', 16, '.merchant-countdown-timer-countdown', '--merchant-digits-font-size', 'px' );
243 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'labels_font_size', 16, '.merchant-countdown-timer-countdown', '--merchant-labels-font-size', 'px' );
244
245 // Sale Ending Color.
246 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'sale_ending_color', '#626262', '.merchant-countdown-timer-text', '--merchant-sale-ending-color' );
247
248 // Digits Color.
249 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_color', '#444444', '.merchant-countdown-timer-countdown', '--merchant-digits-color' );
250
251 // Digits Background Color.
252 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_background', '#fff', '.merchant-countdown-timer-countdown', '--merchant-digits-background' );
253
254 // Progress Color.
255 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'progress_color', '#3858E9', 'body', '--merchant-progress-color' );
256
257 // Labels Color.
258 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'labels_color', '#444444', '.merchant-countdown-timer-countdown', '--merchant-labels-color' );
259
260 // Border Color.
261 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_border', '#444444', '.merchant-countdown-timer-countdown', '--merchant-digits-border' );
262
263 // Digits width & height
264 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_width', 80, '.merchant-countdown-timer-countdown', '--merchant-digits-width', 'px' );
265 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'digits_height', 80, '.merchant-countdown-timer-countdown', '--merchant-digits-height', 'px' );
266
267 // Icon Color.
268 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon_color', '#626262', '.merchant-countdown-timer svg', '--merchant-icon-color' );
269
270 return $css;
271 }
272
273 /**
274 * Admin custom CSS.
275 *
276 * @param string $css The custom CSS.
277 *
278 * @return string $css The custom CSS.
279 */
280 public function admin_custom_css( $css ) {
281 $css .= $this->get_module_custom_css();
282
283 return $css;
284 }
285 }
286
287 // Initialize the module.
288 add_action( 'init', function () {
289 Merchant_Modules::create_module( new Merchant_Countdown_Timer() );
290 } );