PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.5
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.5
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 / clear-cart / class-clear-cart.php

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

706 lines 23.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Clear Cart.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Clear Cart Class.
15 *
16 */
17 class Merchant_Clear_Cart extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'clear-cart';
24
25 /**
26 * Is module preview.
27 *
28 */
29 public static $is_module_preview = false;
30
31 /**
32 * Whether the module has a shortcode or not.
33 *
34 * @var bool
35 */
36 public $has_shortcode = true;
37
38 /**
39 * Constructor.
40 *
41 */
42 public function __construct() {
43 if ( ! class_exists( 'Woocommerce' ) ) {
44 return;
45 }
46
47 // Module id.
48 $this->module_id = self::MODULE_ID;
49
50 // WooCommerce only.
51 $this->wc_only = true;
52
53 // Module section.
54 $this->module_section = 'improve-experience';
55
56 // Parent construct.
57 parent::__construct();
58
59 // Module default settings.
60 $this->module_default_settings = array(
61 'cart_threshold' => 1,
62 'enable_auto_clear' => false,
63 'auto_clear_expiration_hours' => 24,
64 'popup_message' => __( 'Are you sure you want to empty your shopping cart?', 'merchant' ),
65 'popup_message_inactive' => __( 'It looks like you haven’t been active for a while. Would you like to empty your shopping cart?', 'merchant' ),
66 'redirect_link' => '',
67 'redirect_link_custom' => '',
68 'enable_cart_page' => true,
69 'cart_page_position' => 'woocommerce_cart_coupon',
70 'enable_mini_cart' => false,
71 'mini_cart_position' => 'after_checkout',
72 'enable_side_cart' => false,
73 'side_cart_position' => 'after_view_cart',
74 'label' => __( 'Clear Cart', 'merchant' ),
75 'style' => 'solid',
76 );
77
78 // Mount preview url.
79 $preview_url = site_url( '/' );
80
81 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
82 $this->module_data['preview_url'] = $preview_url;
83
84 // Module options path.
85 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
86
87 // Is module preview page.
88 if ( is_admin() && parent::is_module_settings_page() ) {
89 self::$is_module_preview = true;
90
91 // Enqueue admin styles.
92 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
93
94 // Enqueue admin scripts.
95 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_js' ) );
96
97 // Admin preview box.
98 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
99
100 // Custom CSS.
101 // The custom CSS should be added here as well due to ensure preview box works properly.
102 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
103 }
104
105 if ( ! Merchant_Modules::is_module_active( self::MODULE_ID ) ) {
106 return;
107 }
108
109 if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
110 $this->init_translations();
111 }
112
113 // Return early if it's on admin but not in the respective module settings page.
114 if ( is_admin() && ! wp_doing_ajax() && ! parent::is_module_settings_page() ) {
115 return;
116 }
117
118 $settings = $this->get_module_settings();
119
120 // Cart Page
121 if ( ! empty( $settings['enable_cart_page'] ) ) {
122 $hook_name = ! empty( $settings['cart_page_position'] ) ? $settings['cart_page_position'] : 'woocommerce_cart_coupon';
123
124 add_action( $hook_name, array( $this, 'button_cart_page' ) );
125 }
126
127 // Mini Cart
128 if ( ! empty( $settings['enable_mini_cart'] ) ) {
129 $position = $settings['mini_cart_position'] ?? 'after_checkout';
130 $hook_priority = $position === 'before_view_cart' ? 9 : ( $position === 'after_view_cart' ? 15 : 30 );
131
132 add_action( 'woocommerce_widget_shopping_cart_buttons', array( $this, 'button_mini_cart' ), $hook_priority );
133 }
134
135 // Side Cart
136 if ( ! empty( $settings['enable_side_cart'] ) && merchant_is_pro_active() && Merchant_Modules::is_module_active( Merchant_Side_Cart::MODULE_ID ) ) {
137 $position = $settings['side_cart_position'] ?? 'after_view_cart';
138 $hook_priority = $position === 'before_view_cart' ? 15 : ( $position === 'before_checkout' ? 30 : 9 );
139
140 // Side Cart
141 add_action( 'merchant_widget_shopping_cart_buttons', array( $this, 'button_side_cart' ), $hook_priority );
142 }
143
144 // Enqueue CSS.
145 add_action( 'merchant_enqueue_before_main_css_js', array( $this, 'enqueue_css' ) );
146
147 // Enqueue scripts.
148 add_action( 'merchant_enqueue_after_main_css_js', array( $this, 'enqueue_scripts' ) );
149
150 // Localize script.
151 add_filter( 'merchant_localize_script', array( $this, 'localize_script' ) );
152
153 // Custom CSS.
154 add_filter( 'merchant_custom_css', array( $this, 'frontend_custom_css' ) );
155
156 add_action( 'wp_ajax_clear_cart', array( $this, 'clear_cart_ajax_handler' ) );
157 add_action( 'wp_ajax_nopriv_clear_cart', array( $this, 'clear_cart_ajax_handler' ) );
158
159 add_filter( 'woocommerce_add_to_cart_fragments', array( $this, 'cart_count_fragment' ) );
160 }
161
162 /**
163 * Init translations.
164 *
165 * @return void
166 */
167 public function init_translations() {
168 $settings = $this->get_module_settings();
169 if ( ! empty( $settings['label'] ) ) {
170 Merchant_Translator::register_string( $settings['label'], esc_html__( 'Clear Cart', 'merchant' ) );
171 }
172 }
173
174 /**
175 * Admin enqueue CSS.
176 *
177 * @return void
178 */
179 public function admin_enqueue_css() {
180 if ( $this->is_module_settings_page() ) {
181 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
182 }
183 }
184
185 /**
186 * Admin enqueue scripts.
187 *
188 * @return void
189 */
190 public function admin_enqueue_js() {
191 if ( $this->is_module_settings_page() ) {
192 wp_enqueue_script( "merchant-{$this->module_id}", MERCHANT_URI . "assets/js/modules/{$this->module_id}/admin/preview.min.js", array( 'jquery' ), MERCHANT_VERSION, true );
193 }
194 }
195
196 /**
197 * Render admin preview
198 *
199 * @param Merchant_Admin_Preview $preview
200 * @param string $module
201 *
202 * @return Merchant_Admin_Preview
203 */
204 public function render_admin_preview( $preview, $module ) {
205 if ( self::MODULE_ID === $module ) {
206 $preview->set_html( array( $this, 'admin_preview_content' ), $this->get_module_settings() );
207
208 // Button Label.
209 $preview->set_text( 'label', '.merchant-clear-cart-button' );
210 }
211
212 return $preview;
213 }
214
215 /**
216 * Admin preview content.
217 *
218 * @return void
219 */
220 public static function admin_preview_content( $settings ) {
221 $products = array(
222 array(
223 'title' => __( 'Product title', 'merchant' ),
224 'price' => '$30',
225 'subtotal' => '$30',
226 ),
227 array(
228 'title' => __( 'Product title', 'merchant' ),
229 'price' => '$55',
230 'subtotal' => '$55',
231 ),
232 );
233
234 ?>
235 <table class="shop_table" cellspacing="0">
236 <thead>
237 <tr>
238 <th class="product-remove"><span class="screen-reader-text"><?php esc_html_e( 'Remove item', 'merchant' ); ?></span></th>
239 <th class="product-thumbnail"><span class="screen-reader-text"><?php esc_html_e( 'Thumbnail image', 'merchant' ); ?></span></th>
240 <th class="product-name"><?php esc_html_e( 'Product', 'merchant' ); ?></th>
241 <th class="product-price"><?php esc_html_e( 'Price', 'merchant' ); ?></th>
242 <th class="product-quantity"><?php esc_html_e( 'Quantity', 'merchant' ); ?></th>
243 <th class="product-subtotal"><?php esc_html_e( 'Total', 'merchant' ); ?></th>
244 </tr>
245 </thead>
246 <tbody>
247 <?php foreach ( $products as $p ) : ?>
248 <tr class="woocommerce-cart-form__cart-item cart_item">
249 <td class="product-remove">
250 <svg width="10" height="10" viewBox="0 0 5 5" fill="none" xmlns="http://www.w3.org/2000/svg">
251 <path d="M0.715086 0.0388184L0.400391 0.353514L2.32277 2.27589L0.400391 4.19827L0.715086 4.51297L2.63747 2.59059L4.55985 4.51297L4.87454 4.19827L2.95216 2.27589L4.87454 0.353514L4.55985 0.0388184L2.63747 1.9612L0.715086 0.0388184Z" fill="#424242"/>
252 </svg>
253 </td>
254 <td class="product-thumbnail"><span></span></td>
255 <td class="product-name"><?php echo esc_html( $p['title'] ); ?></td>
256 <td class="product-price"><?php echo esc_html( $p['price'] ); ?></td>
257 <td class="product-quantity">
258 <div class="merchant-preview-qty">
259 <button>+</button>
260 <input type="text" value="1">
261 <button>-</button>
262 </div>
263 </td>
264 <td class="product-subtotal"><?php echo esc_html( $p['subtotal'] ); ?></td>
265 </tr>
266 <?php endforeach; ?>
267 </tbody>
268 </table>
269 <div class="shop_table-bottom">
270 <div class="shop_table-bottom__start">
271 <div class="shop_table__coupon">
272 <input type="text" placeholder="<?php echo esc_attr__( 'Coupon Code', 'merchant' ); ?>">
273 <button class="shop_table__button shop_table__button__apply-coupon"><?php echo esc_html__( 'Apply Coupon', 'merchant' ); ?></button>
274 </div>
275 <div class="shop_table__clear-cart">
276 <button class="hide shop_table__button merchant-clear-cart-button woocommerce_cart_coupon"><?php echo esc_html( $settings['label'] ); ?></button>
277 </div>
278 </div>
279 <div class="shop_table-bottom__end">
280 <button class="shop_table__button shop_table__button__update-cart"><?php echo esc_html__( 'Update Cart', 'merchant' ); ?></button>
281 <button class="hide shop_table__button merchant-clear-cart-button woocommerce_cart_actions"><?php echo esc_html( $settings['label'] ); ?></button>
282 </div>
283 </div>
284 <button class="hide shop_table__button merchant-clear-cart-button woocommerce_after_cart_table"><?php echo esc_html( $settings['label'] ); ?></button>
285 <?php
286 }
287
288 /**
289 * Print shortcode content.
290 *
291 * @return string
292 */
293 public function shortcode_handler() {
294 // Check if module is active.
295 if ( ! Merchant_Modules::is_module_active( self::MODULE_ID ) ) {
296 return '';
297 }
298
299 // Check if shortcode is enabled.
300 if ( ! $this->is_shortcode_enabled() ) {
301 return '';
302 }
303
304 ob_start();
305 $this->print_button();
306 $shortcode_content = ob_get_clean();
307
308 /**
309 * Filter the shortcode html content.
310 *
311 * @param string $shortcode_content shortcode html content
312 * @param string $module_id module id
313 * @param int $post_id product id
314 *
315 * @since 1.8
316 */
317 return apply_filters( 'merchant_module_shortcode_content_html', $shortcode_content, self::MODULE_ID, get_the_ID() );
318 }
319
320 /**
321 * Display Button on Cart Page
322 *
323 * @return void
324 */
325 public function button_cart_page() {
326 if ( $this->is_shortcode_enabled() ) {
327 return;
328 }
329
330 $this->print_button( 'cart-page' );
331 }
332
333 /**
334 * Display Button on Side Cart
335 *
336 * @return void
337 */
338 public function button_side_cart() {
339 if ( $this->is_shortcode_enabled() ) {
340 return;
341 }
342
343 $this->print_button( 'side-cart' );
344 }
345
346 /**
347 * Display Button on Mini Cart
348 *
349 * @return void
350 */
351 public function button_mini_cart() {
352 if ( $this->is_shortcode_enabled() ) {
353 return;
354 }
355
356 $this->print_button( 'mini-cart' );
357 }
358
359 /**
360 * Display Button
361 *
362 * @param $context
363 *
364 * @return void
365 */
366 public function print_button( $context = '' ) {
367 $settings = $this->get_module_settings();
368 $threshold = $settings['cart_threshold'] ?? 1;
369
370 // Early return if the cart item count is less than the threshold
371 if ( WC()->cart->get_cart_contents_count() < $threshold ) {
372 return;
373 }
374
375 $theme = wp_get_theme();
376 $theme_name = $theme->get( 'Name' );
377
378 $is_enabled_cart_page = $settings['enable_cart_page'] ?? true;
379 $cart_page_position = $settings['cart_page_position'] ?? 'woocommerce_cart_coupon';
380
381 $label = $settings['label'] ?? esc_html__( 'Clear Cart', 'merchant' );
382 $style = $settings['style'] ?? 'solid';
383
384 $classes = 'merchant-clear-cart-button';
385 $classes .= ' merchant-clear-cart-button--' . $style;
386 $classes .= $context ? ' merchant-clear-cart-button--' . $context : '';
387 $classes .= $context === 'cart-page' ? ' ' . ( $settings['cart_page_position'] ?? 'woocommerce_cart_coupon' ) : '';
388 ?>
389 <button type="button" class="button<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?> <?php echo esc_attr( $classes ); ?>">
390 <?php echo esc_html( $label ); ?>
391 </button>
392 <?php
393 // Because of a CSS issue, adding extra Update cart button on Botiga. Default one hidden by CSS.
394 if ( $context === 'cart-page' && $theme_name === 'Botiga' && ! $this->is_shortcode_enabled() && $is_enabled_cart_page && $cart_page_position === 'woocommerce_cart_actions' ) {
395 ?>
396 <button type="submit" class="button<?php echo esc_attr( wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '' ); ?> merchant-clear-cart-button__update-cart" name="update_cart" value="<?php esc_attr_e( 'Update cart', 'merchant' ); ?>"><?php esc_html_e( 'Update cart', 'merchant' ); ?></button>
397 <?php
398 }
399 }
400
401 /**
402 * Cart count fragments.
403 *
404 * @param $fragments
405 *
406 * @return mixed
407 */
408 public function cart_count_fragment( $fragments ) {
409 $fragments['.merchant_clear_cart_cart_count'] = WC()->cart->get_cart_contents_count();
410
411 return $fragments;
412 }
413
414 /**
415 * Clear Cart AJAX
416 *
417 * @return void
418 */
419 public function clear_cart_ajax_handler() {
420 check_ajax_referer( 'merchant-nonce', 'nonce' );
421
422 if ( WC()->cart && ! WC()->cart->is_empty() ) {
423 $settings = $this->get_module_settings();
424
425 $redirect_url = '';
426 $redirect_link = $settings['redirect_link'] ?? '';
427
428 switch ( $redirect_link ) {
429 case 'home':
430 $redirect_url = home_url();
431 break;
432
433 case 'shop':
434 $redirect_url = wc_get_page_permalink( 'shop' );
435 break;
436
437 case 'custom':
438 $custom_link = $settings['redirect_link_custom'] ?? '';
439 $redirect_url = ! empty( $custom_link ) ? esc_url( $custom_link ) : '';
440 break;
441 }
442
443 WC()->cart->empty_cart();
444 wp_send_json_success( array( 'url' => $redirect_url ) );
445 }
446
447 wp_send_json_error( array( 'message' => esc_html__( 'Cart is Empty.', 'merchant' ) ) );
448 }
449
450 /**
451 * Determine if assets should be enqueued.
452 *
453 * @return bool
454 */
455 private function should_load_assets() {
456 $settings = $this->get_module_settings();
457
458 // Check if auto-clear is enabled or if the shortcode is being used
459 $load_assets = ( $settings['enable_auto_clear'] ?? false ) || $this->is_shortcode_enabled();
460
461 // Check additional conditions: cart page, mini cart, or side cart enabled
462 $load_assets = $load_assets || ( $settings['enable_cart_page'] && is_cart() ) || $settings['enable_mini_cart'] || $settings['enable_side_cart'];
463
464 return $load_assets;
465 }
466
467 /**
468 * Enqueue CSS.
469 *
470 * @return void
471 */
472 public function enqueue_css() {
473 if ( ! $this->should_load_assets() ) {
474 return;
475 }
476
477 // Specific module styles.
478 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/clear-cart.min.css', array(), MERCHANT_VERSION );
479 }
480
481 /**
482 * Enqueue scripts.
483 *
484 * @return void
485 */
486 public function enqueue_scripts() {
487 if ( ! $this->should_load_assets() ) {
488 return;
489 }
490
491 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/clear-cart.min.js', array( 'jquery' ), MERCHANT_VERSION, true );
492 }
493
494 /**
495 * Localize script with module settings.
496 *
497 * @param array $setting The merchant global object setting parameter.
498 * @return array $setting The merchant global object setting parameter.
499 */
500 public function localize_script( $setting ) {
501 if ( ! $this->should_load_assets() ) {
502 return $setting;
503 }
504
505 $module_settings = $this->get_module_settings();
506
507 $expiration_in_hours = (int) ( $module_settings['auto_clear_expiration_hours'] ?? 24 );
508 $expiration_in_seconds = $expiration_in_hours * 60 * 60;
509
510 $setting['clear_cart'] = array(
511 'threshold' => (int) ( $module_settings['cart_threshold'] ?? 1 ),
512 'auto_clear' => (bool) ( $module_settings['enable_auto_clear'] ?? false ),
513 'expiration_time' => $expiration_in_seconds,
514 'wc_session_expiration_time' => DAY_IN_SECONDS * 2, // Default 48h,
515 'popup_message' => $module_settings['popup_message'] ?? '',
516 'popup_message_inactive' => $module_settings['popup_message_inactive'] ?? '',
517 'is_cart_page' => is_cart(),
518 'is_product_single' => is_product(),
519 'added_to_cart_no_ajax' => ! empty( $_REQUEST['add-to-cart'] ) || ! empty( $_REQUEST['botiga-adtc-added-to-cart'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
520 'total_items' => WC()->cart->get_cart_contents_count(),
521 );
522
523 return $setting;
524 }
525
526 /**
527 * Admin custom CSS.
528 *
529 * @param string $css The custom CSS.
530 * @return string $css The custom CSS.
531 */
532 public function admin_custom_css( $css ) {
533 $css .= $this->get_module_custom_css();
534
535 return $css;
536 }
537
538 /**
539 * Frontend custom CSS.
540 *
541 * @param string $css The custom CSS.
542 * @return string $css The custom CSS.
543 */
544 public function frontend_custom_css( $css ) {
545 if ( ! $this->should_load_assets() ) {
546 return $css;
547 }
548
549 $settings = $this->get_module_settings();
550
551 $is_enabled_cart_page = $settings['enable_cart_page'] ?? true;
552 $cart_page_position = $settings['cart_page_position'] ?? 'woocommerce_cart_coupon';
553 $is_enabled_mini_cart = $settings['enable_mini_cart'] ?? false;
554
555 $theme = wp_get_theme();
556 $theme_name = $theme->get( 'Name' );
557
558 $css .= $this->get_module_custom_css();
559
560 if ( $theme_name === 'Botiga' && ! $this->is_shortcode_enabled() ) {
561 if ( $is_enabled_mini_cart ) {
562 $css .= '
563 #site-header-cart button.merchant-clear-cart-button {
564 color: var(--mrc-clear-cart-text-color, #ffffff);
565 font-size: var(--mrc-clear-cart-font-size, 16px) !important;
566 padding-block: var(--mrc-clear-cart-padding-vertical, 13px) !important;
567 padding-inline: var(--mrc-clear-cart-padding-horizontal, 25px) !important;
568 margin-top: 5px;
569 text-decoration: none;
570 }
571
572 #site-header-cart button.merchant-clear-cart-button:hover {
573 background: none;
574 color: var(--mrc-clear-cart-text-color-hover, #ffffff);
575 }
576
577 #site-header-cart button.merchant-clear-cart-button--solid,
578 #site-header-cart button.merchant-clear-cart-button--outline {
579 margin-top: 15px;
580 }
581
582 #site-header-cart button.merchant-clear-cart-button--solid {
583 background-color: var(--mrc-clear-cart-bg-color, #212121) !important;
584 }
585
586 #site-header-cart button.merchant-clear-cart-button--solid:hover {
587 background-color: var(--mrc-clear-cart-bg-color-hover, #414141) !important;
588 }
589
590 #site-header-cart button.merchant-clear-cart-button--outline {
591 border: 2px solid var(--mrc-clear-cart-border-color, #212121);
592 }
593
594 #site-header-cart button.merchant-clear-cart-button--outline:hover {
595 border-color: var(--mrc-clear-cart-border-color-hover, #414141);
596 }
597 ';
598 }
599
600 // After Coupon
601 if ( $is_enabled_cart_page && $cart_page_position === 'woocommerce_cart_coupon' ) {
602 $css .= '@media (max-width: 767px) {';
603 $css .= '
604 .woocommerce-cart .woocommerce-cart-form .actions .coupon {
605 flex-wrap: wrap;
606 }
607
608 ';
609 $css .= '}';
610
611 $css .= '@media (max-width: 575px) {';
612 $css .= '
613 .button.merchant-clear-cart-button {
614 min-width: 100%;
615 margin-top: 10px;
616 }
617 ';
618 $css .= '}';
619 }
620
621 // After Update Cart Button
622 if ( $is_enabled_cart_page && $cart_page_position === 'woocommerce_cart_actions' ) {
623 $css .= '
624 .shop_table .button[name="update_cart"]:not(.merchant-clear-cart-button__update-cart) {
625 display: none;
626 }
627 ';
628
629 $css .= '@media (max-width: 767px) {';
630 $css .= '
631 .button.merchant-clear-cart-button {
632 margin-top: 15px;
633 margin-left: 10px;
634 }
635 ';
636 $css .= '}';
637
638 $css .= '@media (max-width: 575px) {';
639 $css .= '
640 .button.merchant-clear-cart-button {
641 width: 100%;
642 margin-top: 15px;
643 margin-left: 0px;
644 }
645 ';
646 $css .= '}';
647 }
648 }
649
650 return $css;
651 }
652
653 /**
654 * Custom CSS.
655 *
656 * @return string
657 */
658 public function get_module_custom_css() {
659 if ( ! $this->should_load_assets() && ! is_admin() ) {
660 return '';
661 }
662
663 $css = '';
664
665 // Background Color.
666 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'background_color', '#212121', '.merchant-clear-cart-button', '--mrc-clear-cart-bg-color' );
667
668 // Background Color(Hover).
669 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'background_color_hover', '#414141', '.merchant-clear-cart-button', '--mrc-clear-cart-bg-color-hover' );
670
671 // Border Width
672 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'border_width', 2, '.merchant-clear-cart-button', '--mrc-clear-cart-border-width', 'px' );
673
674 // Border Color
675 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'border_color', '#212121', '.merchant-clear-cart-button', '--mrc-clear-cart-border-color' );
676
677 // Border Color(Hover).
678 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'border_color_hover', '#414141', '.merchant-clear-cart-button', '--mrc-clear-cart-border-color-hover' );
679
680 // Border radius.
681 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'border_radius', 0, '.merchant-clear-cart-button', '--mrc-clear-cart-border-radius', 'px' );
682
683 // Text Color.
684 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'text_color', '#ffffff', '.merchant-clear-cart-button', '--mrc-clear-cart-text-color' );
685
686 // Text Color(Hover).
687 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'text_color_hover', '#ffffff', '.merchant-clear-cart-button', '--mrc-clear-cart-text-color-hover' );
688
689 // Font Size.
690 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'font_size', 16, '.merchant-clear-cart-button', '--mrc-clear-cart-font-size', 'px' );
691
692 // Padding Top/Bottom.
693 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'padding_vertical', 15, '.merchant-clear-cart-button', '--mrc-clear-cart-padding-vertical', 'px' );
694
695 // Padding Left/Right.
696 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'padding_horizontal', 25, '.merchant-clear-cart-button', '--mrc-clear-cart-padding-horizontal', 'px' );
697
698 return $css;
699 }
700 }
701
702 // Initialize the module.
703 add_action( 'init', static function () {
704 Merchant_Modules::create_module( new Merchant_Clear_Cart() );
705 } );
706