| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Side Cart |
| 5 |
* |
| 6 |
* @package Merchant |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Side Cart Class. |
| 15 |
* |
| 16 |
*/ |
| 17 |
class Merchant_Side_Cart extends Merchant_Add_Module { |
| 18 |
|
| 19 |
/** |
| 20 |
* Module ID. |
| 21 |
*/ |
| 22 |
const MODULE_ID = 'side-cart'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Module template path. |
| 26 |
*/ |
| 27 |
const MODULE_TEMPLATES_PATH = 'modules/' . self::MODULE_ID; |
| 28 |
|
| 29 |
/** |
| 30 |
* Is module preview. |
| 31 |
* |
| 32 |
*/ |
| 33 |
public static $is_module_preview = false; |
| 34 |
|
| 35 |
/** |
| 36 |
* Constructor. |
| 37 |
* |
| 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 |
$this->migrate_floating_mini_cart_to_side_cart(); // Run on both BE & FE |
| 50 |
|
| 51 |
// Module default settings. |
| 52 |
$this->module_default_settings = array( |
| 53 |
'show_after_add_to_cart' => 1, |
| 54 |
'show_after_add_to_cart_single_product' => 0, |
| 55 |
'show_on_cart_url_click' => 1, |
| 56 |
'enable-floating-cart' => false, |
| 57 |
'show_view_cart_btn' => true, |
| 58 |
'show_checkout_btn' => true, |
| 59 |
); |
| 60 |
|
| 61 |
// Module data. |
| 62 |
$this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ]; |
| 63 |
|
| 64 |
// Module section. |
| 65 |
$this->module_section = $this->module_data['section']; |
| 66 |
|
| 67 |
// Module options path. |
| 68 |
$this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; |
| 69 |
if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) { |
| 70 |
// Init translations. |
| 71 |
$this->init_translations(); |
| 72 |
} |
| 73 |
|
| 74 |
// Is module preview page. |
| 75 |
if ( is_admin() && parent::is_module_settings_page() ) { |
| 76 |
self::$is_module_preview = true; |
| 77 |
|
| 78 |
// Enqueue admin styles. |
| 79 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) ); |
| 80 |
|
| 81 |
// Enqueue admin scripts. |
| 82 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 83 |
|
| 84 |
// Admin preview box. |
| 85 |
add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 ); |
| 86 |
|
| 87 |
// Custom CSS. |
| 88 |
add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) ); |
| 89 |
|
| 90 |
add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
public function init_translations() { |
| 95 |
$settings = $this->get_module_settings(); |
| 96 |
if ( ! empty( $settings['checkout_btn_text'] ) ) { |
| 97 |
Merchant_Translator::register_string( $settings['checkout_btn_text'], esc_html__( 'Side cart checkout button text', 'merchant' ) ); |
| 98 |
} |
| 99 |
if ( ! empty( $settings['view_cart_btn_text'] ) ) { |
| 100 |
Merchant_Translator::register_string( $settings['view_cart_btn_text'], esc_html__( 'Side cart view cart button text', 'merchant' ) ); |
| 101 |
} |
| 102 |
if ( ! empty( $settings['upsells_title'] ) ) { |
| 103 |
Merchant_Translator::register_string( $settings['upsells_title'], esc_html__( 'Side cart upsells title', 'merchant' ) ); |
| 104 |
} |
| 105 |
if ( ! empty( $settings['upsells_add_to_cart_text'] ) ) { |
| 106 |
Merchant_Translator::register_string( $settings['upsells_add_to_cart_text'], esc_html__( 'Side cart upsells add to cart text', 'merchant' ) ); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Admin enqueue CSS. |
| 112 |
* |
| 113 |
* @return void |
| 114 |
*/ |
| 115 |
public function admin_enqueue_css() { |
| 116 |
if ( $this->is_module_settings_page() ) { |
| 117 |
wp_enqueue_style( |
| 118 |
'merchant-' . self::MODULE_ID, |
| 119 |
MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/side-cart.min.css', |
| 120 |
array(), |
| 121 |
MERCHANT_VERSION |
| 122 |
); |
| 123 |
|
| 124 |
wp_enqueue_style( |
| 125 |
'merchant-admin-preview-' . self::MODULE_ID, |
| 126 |
MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', |
| 127 |
array(), |
| 128 |
MERCHANT_VERSION |
| 129 |
); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Admin Enqueue scripts. |
| 135 |
* |
| 136 |
* @return void |
| 137 |
*/ |
| 138 |
public function admin_enqueue_scripts() { |
| 139 |
wp_enqueue_script( |
| 140 |
'merchant-' . self::MODULE_ID, |
| 141 |
MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/side-cart.min.js', |
| 142 |
array(), |
| 143 |
MERCHANT_VERSION, |
| 144 |
true |
| 145 |
); |
| 146 |
|
| 147 |
wp_enqueue_script( |
| 148 |
'merchant-preview-' . self::MODULE_ID, |
| 149 |
MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/admin/preview.min.js', |
| 150 |
array(), |
| 151 |
MERCHANT_VERSION, |
| 152 |
true |
| 153 |
); |
| 154 |
|
| 155 |
wp_localize_script( 'merchant-preview-' . self::MODULE_ID, 'merchant_side_cart_params', array( |
| 156 |
'keywords' => array( |
| 157 |
'multi_categories' => esc_html__( 'Multi Categories', 'merchant' ), |
| 158 |
'category_trigger' => esc_html__( 'Category Trigger:', 'merchant' ), |
| 159 |
'no_cats_selected' => esc_html__( 'No Categories Selected', 'merchant' ), |
| 160 |
'no_products_selected' => esc_html__( 'No Products Selected', 'merchant' ), |
| 161 |
'multi_products' => esc_html__( 'Multi Products', 'merchant' ), |
| 162 |
'all_products' => esc_html__( 'All Products', 'merchant' ), |
| 163 |
), |
| 164 |
) ); |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
/** |
| 169 |
* Render admin preview |
| 170 |
* |
| 171 |
* @param Merchant_Admin_Preview $preview |
| 172 |
* @param string $module |
| 173 |
* |
| 174 |
* @return Merchant_Admin_Preview |
| 175 |
*/ |
| 176 |
public function render_admin_preview( $preview, $module ) { |
| 177 |
if ( $module === self::MODULE_ID ) { |
| 178 |
ob_start(); |
| 179 |
self::admin_preview_content(); |
| 180 |
$content = ob_get_clean(); |
| 181 |
|
| 182 |
// HTML. |
| 183 |
$preview->set_html( $content ); |
| 184 |
|
| 185 |
// View Cart button |
| 186 |
$preview->set_text( 'view_cart_btn_text', '.merchant-side-cart-view-cart-btn' ); |
| 187 |
|
| 188 |
// Checkout button |
| 189 |
$preview->set_text( 'checkout_btn_text', '.merchant-side-cart-checkout-btn' ); |
| 190 |
|
| 191 |
// Icon visibility |
| 192 |
$preview->set_class( 'enable-floating-cart', '.merchant-side-cart-floating-cart', array(), 'merchant-show' ); |
| 193 |
|
| 194 |
// Icon. |
| 195 |
$preview->set_svg_icon( 'icon', '.merchant-side-cart-floating-cart-icon' ); |
| 196 |
|
| 197 |
// Position. |
| 198 |
$preview->set_class( 'icon-position', '.merchant-side-cart-floating-cart', array( 'merchant-side-cart-floating-cart-position-left', 'merchant-side-cart-floating-cart-position-right' ) ); |
| 199 |
|
| 200 |
$preview->set_class( 'show_view_cart_btn', '.merchant-side-cart-view-cart-btn', array(), 'show-btn' ); |
| 201 |
$preview->set_class( 'show_checkout_btn', '.merchant-side-cart-checkout-btn', array(), 'show-btn' ); |
| 202 |
} |
| 203 |
|
| 204 |
return $preview; |
| 205 |
} |
| 206 |
|
| 207 |
/** |
| 208 |
* Admin preview content. |
| 209 |
* |
| 210 |
* @return void |
| 211 |
*/ |
| 212 |
public function admin_preview_content() { |
| 213 |
$settings = $this->get_module_settings(); |
| 214 |
|
| 215 |
?> |
| 216 |
<div class="mrc-preview-single-product-elements"> |
| 217 |
<div class="mrc-preview-left-column"> |
| 218 |
<div class="mrc-preview-product-image-wrapper"> |
| 219 |
<div class="mrc-preview-product-image"></div> |
| 220 |
<div class="mrc-preview-product-image-thumbs"> |
| 221 |
<div class="mrc-preview-product-image-thumb"></div> |
| 222 |
<div class="mrc-preview-product-image-thumb"></div> |
| 223 |
<div class="mrc-preview-product-image-thumb"></div> |
| 224 |
</div> |
| 225 |
</div> |
| 226 |
</div> |
| 227 |
<div class="mrc-preview-right-column"> |
| 228 |
<div class="mrc-preview-text-placeholder"></div> |
| 229 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 230 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 231 |
<div class="mrc-preview-text-placeholder"></div> |
| 232 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 233 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 234 |
<div class="mrc-preview-text-placeholder"></div> |
| 235 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 236 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 237 |
<div class="mrc-preview-text-placeholder"></div> |
| 238 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 239 |
<div class="mrc-preview-addtocart-placeholder"></div> |
| 240 |
</div> |
| 241 |
</div> |
| 242 |
|
| 243 |
<?php |
| 244 |
$icon_classes = 'merchant-side-cart-floating-cart merchant-side-cart-floating-cart-position-' . ( $settings['icon-position'] ?? 'right' ) ; |
| 245 |
$icon_classes .= ! empty( $settings['enable-floating-cart'] ) ? ' merchant-show' : ''; |
| 246 |
$icon_classes .= ' js-merchant-side-cart-toggle-handler'; |
| 247 |
?> |
| 248 |
<a href="#" class="<?php echo esc_attr( $icon_classes ); ?>"> |
| 249 |
<span class="merchant-side-cart-floating-cart-counter"><?php echo esc_attr( 2 ); ?></span> |
| 250 |
<i class="merchant-side-cart-floating-cart-icon"><?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( $settings['icon'] ?? 'cart-icon-1' ), merchant_kses_allowed_tags( array(), false ) ); ?></i> |
| 251 |
</a> |
| 252 |
|
| 253 |
<div class="merchant-side-cart-wrapper"> |
| 254 |
<div class="merchant-side-cart-overlay"></div> |
| 255 |
<div class="merchant-side-cart <?php echo esc_attr( 'slide-' . ( $settings['slide_direction'] ?? 'right' ) ); ?>"> |
| 256 |
<div class="merchant-side-cart-body"> |
| 257 |
<a href="#" class="merchant-side-cart-close-button js-merchant-side-cart-toggle-handler" |
| 258 |
title="<?php |
| 259 |
echo esc_attr__( 'Close the side mini cart', 'merchant' ); ?>"> |
| 260 |
<?php |
| 261 |
echo wp_kses( Merchant_SVG_Icons::get_svg_icon( 'icon-cancel' ), merchant_kses_allowed_tags( array(), false ) ); ?> |
| 262 |
</a> |
| 263 |
|
| 264 |
<div class="merchant-side-cart-widget"> |
| 265 |
<div class="merchant-side-cart-widget-title"><?php |
| 266 |
echo esc_html__( 'Your Cart', 'merchant' ); ?></div> |
| 267 |
<div class="widget_shopping_cart_content"> |
| 268 |
<ul class="woocommerce-mini-cart cart_list product_list_widget"> |
| 269 |
<li class="woocommerce-mini-cart-item mini_cart_item"> |
| 270 |
<a href="#" class="remove remove_from_cart_button">×</a> |
| 271 |
<a href="#"> |
| 272 |
<span class="mrc-product-image"></span> |
| 273 |
<?php |
| 274 |
echo esc_html__( 'Product Sample Title', 'merchant' ); ?> |
| 275 |
</a> |
| 276 |
<span class="quantity">1 × |
| 277 |
<span class="woocommerce-Price-amount amount"> |
| 278 |
<bdi><span class="woocommerce-Price-currencySymbol">$</span>12.00 </bdi> |
| 279 |
</span> |
| 280 |
</span> |
| 281 |
</li> |
| 282 |
<li class="woocommerce-mini-cart-item mini_cart_item"> |
| 283 |
<a href="#" class="remove remove_from_cart_button">×</a> |
| 284 |
<a href="#"> |
| 285 |
<span class="mrc-product-image"></span> |
| 286 |
<?php |
| 287 |
echo esc_html__( 'Product Sample Title', 'merchant' ); ?> |
| 288 |
</a> |
| 289 |
<span class="quantity">1 × |
| 290 |
<span class="woocommerce-Price-amount amount"> |
| 291 |
<bdi><span class="woocommerce-Price-currencySymbol">$</span>12.00 </bdi> |
| 292 |
</span> |
| 293 |
</span> |
| 294 |
</li> |
| 295 |
</ul> |
| 296 |
|
| 297 |
<p class="woocommerce-mini-cart__total total"> |
| 298 |
<strong><?php |
| 299 |
echo esc_html__( 'Subtotal:', 'merchant' ); ?></strong> |
| 300 |
<span class="woocommerce-Price-amount amount"> |
| 301 |
<bdi><span class="woocommerce-Price-currencySymbol">$</span>12.00 </bdi> |
| 302 |
</span> |
| 303 |
</p> |
| 304 |
<p class="woocommerce-mini-cart__buttons buttons"> |
| 305 |
<a href="#" class="button wc-forward merchant-side-cart-view-cart-btn<?php echo esc_attr( ! empty( $settings['show_view_cart_btn'] ) ) ? ' show-btn' : ''; ?>"><?php echo esc_html( $settings['view_cart_btn_text'] ?? 'View Cart' ); ?></a> |
| 306 |
<a href="#" class="button checkout wc-forward merchant-side-cart-checkout-btn<?php echo esc_attr( ! empty( $settings['show_checkout_btn'] ) ) ? ' show-btn' : ''; ?>"><?php echo esc_html( $settings['checkout_btn_text'] ?? 'Checkout' ); ?></a> |
| 307 |
</p> |
| 308 |
</div> |
| 309 |
</div> |
| 310 |
</div> |
| 311 |
</div> |
| 312 |
</div> |
| 313 |
<?php |
| 314 |
} |
| 315 |
|
| 316 |
/** |
| 317 |
* Add class to body in admin. |
| 318 |
* |
| 319 |
* @param $classes |
| 320 |
* |
| 321 |
* @return string |
| 322 |
*/ |
| 323 |
public function admin_body_class( $classes ) { |
| 324 |
$classes .= ' merchant-side-cart-show'; |
| 325 |
|
| 326 |
return $classes; |
| 327 |
} |
| 328 |
|
| 329 |
/** |
| 330 |
* Admin custom CSS. |
| 331 |
* |
| 332 |
* @param string $css The custom CSS. |
| 333 |
* |
| 334 |
* @return string $css The custom CSS. |
| 335 |
*/ |
| 336 |
public function admin_custom_css( $css ) { |
| 337 |
$css .= self::get_module_custom_css(); |
| 338 |
|
| 339 |
return $css; |
| 340 |
} |
| 341 |
|
| 342 |
/** |
| 343 |
* Custom CSS. |
| 344 |
* |
| 345 |
* @return string |
| 346 |
*/ |
| 347 |
public static function get_module_custom_css() { |
| 348 |
$css = ''; |
| 349 |
|
| 350 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-size', 25, '.merchant-side-cart-floating-cart', '--mrc-fmci-icon-size', 'px' ); |
| 351 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-corner-offset', 30, '.merchant-side-cart-floating-cart', '--mrc-fmci-corner-offset', 'px' ); |
| 352 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-position', 'right', '.merchant-side-cart-floating-cart', '--mrc-fmci-icon-position' ); |
| 353 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-border-radius', 35, '.merchant-side-cart-floating-cart-icon', '--mrc-fmci-border-radius', 'px' ); |
| 354 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-color', '#ffffff', '.merchant-side-cart-floating-cart-icon', '--mrc-fmci-icon-color' ); |
| 355 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-background-color', '#212121', '.merchant-side-cart-floating-cart-icon', '--mrc-fmci-background-color' ); |
| 356 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-counter-color', '#ffffff', '.merchant-side-cart-floating-cart-counter', '--mrc-fmci-counter-color' ); |
| 357 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-counter-background-color', '#757575', '.merchant-side-cart-floating-cart-counter', '--mrc-fmci-counter-background-color' ); |
| 358 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-width', 380, '.merchant-side-cart', '--mrc-fmci-side-cart-width', 'px' ); |
| 359 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-title-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-title-color' ); |
| 360 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-title-icon-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-title-icon-color' ); |
| 361 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-title-background-color', '#cccccc', '.merchant-side-cart', '--mrc-fmci-side-cart-title-background-color' ); |
| 362 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-content-text-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-content-text-color' ); |
| 363 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-content-background-color', '#ffffff', '.merchant-side-cart', '--mrc-fmci-side-cart-content-background-color' ); |
| 364 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-content-remove-color', '#ffffff', '.merchant-side-cart', '--mrc-fmci-side-cart-content-remove-color' ); |
| 365 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-content-remove-background-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-content-remove-background-color' ); |
| 366 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-total-text-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-total-text-color' ); |
| 367 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-total-background-color', '#f5f5f5', '.merchant-side-cart', '--mrc-fmci-side-cart-total-background-color' ); |
| 368 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-button-color', '#ffffff', '.merchant-side-cart', '--mrc-fmci-side-cart-button-color' ); |
| 369 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-button-color-hover', '#ffffff', '.merchant-side-cart', '--mrc-fmci-side-cart-button-color-hover' ); |
| 370 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-button-border-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-button-border-color' ); |
| 371 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-button-border-color-hover', '#313131', '.merchant-side-cart', '--mrc-fmci-side-cart-button-border-color-hover' ); |
| 372 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-button-background-color', '#212121', '.merchant-side-cart', '--mrc-fmci-side-cart-button-background-color' ); |
| 373 |
$css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'side-cart-button-background-color-hover', '#313131', '.merchant-side-cart', '--mrc-fmci-side-cart-button-background-color-hover' ); |
| 374 |
|
| 375 |
return $css; |
| 376 |
} |
| 377 |
|
| 378 |
/** |
| 379 |
* Merge Some Floating Mini Cart Settings to Side Cart |
| 380 |
* |
| 381 |
* @return void |
| 382 |
*/ |
| 383 |
private function migrate_floating_mini_cart_to_side_cart() { |
| 384 |
if ( get_option( 'merchant_floating_mini_cart_merged_with_side_cart', false ) || ! method_exists( 'Merchant_Admin_Options', 'set' ) ) { |
| 385 |
return; |
| 386 |
} |
| 387 |
|
| 388 |
// Floating Mini Cart |
| 389 |
$fmc_module_id = 'floating-mini-cart'; |
| 390 |
$is_fmc_enabled = Merchant_Modules::is_module_active( $fmc_module_id ); |
| 391 |
if ( $is_fmc_enabled ) { |
| 392 |
$fmc_settings = Merchant_Admin_Options::get_all( $fmc_module_id ); |
| 393 |
|
| 394 |
// Map Side cart options data by Floating Mini Cart options. |
| 395 |
$side_cart_options = array( |
| 396 |
'enable-floating-cart' => true, |
| 397 |
'icon-display' => sanitize_text_field( $fmc_settings['display'] ?? 'always' ), |
| 398 |
'icon' => sanitize_text_field( $fmc_settings['icon'] ?? 'cart-icon-1' ), |
| 399 |
'icon-position' => sanitize_text_field( $fmc_settings['icon-position'] ?? 'right' ), |
| 400 |
'icon-size' => absint( $fmc_settings['icon-size'] ?? 25 ), |
| 401 |
'icon-corner-offset' => absint( $fmc_settings['corner-offset'] ?? 30 ), |
| 402 |
'icon-border-radius' => absint( $fmc_settings['border-radius'] ?? 35 ), |
| 403 |
'icon-color' => sanitize_hex_color( $fmc_settings['icon-color'] ?? '#ffffff' ), |
| 404 |
'icon-background-color' => sanitize_hex_color( $fmc_settings['background-color'] ?? '#212121' ), |
| 405 |
'icon-counter-color' => sanitize_hex_color( $fmc_settings['counter-color'] ?? '#ffffff' ), |
| 406 |
'icon-counter-background-color' => sanitize_hex_color( $fmc_settings['counter-background-color'] ?? '#757575' ), |
| 407 |
); |
| 408 |
|
| 409 |
// Update the Side Cart options. |
| 410 |
foreach ( $side_cart_options as $key => $value ) { |
| 411 |
Merchant_Admin_Options::set( self::MODULE_ID, $key, $value ); |
| 412 |
} |
| 413 |
} |
| 414 |
|
| 415 |
// Free Shipping Bar - Field options ids were changed. So map old ids to the new ids. |
| 416 |
$fsb_module_id = 'free-shipping-progress-bar'; |
| 417 |
$is_fsb_enabled = Merchant_Modules::is_module_active( $fsb_module_id ); |
| 418 |
if ( $is_fsb_enabled ) { |
| 419 |
$side_cart_placement = Merchant_Admin_Options::get( $fsb_module_id, 'side_cart_placement', 'merchant_widget_shopping_cart_before_buttons' ); |
| 420 |
|
| 421 |
// Define the old-to-new placement mappings |
| 422 |
$placement_mapping = array( |
| 423 |
'woocommerce_before_mini_cart_contents' => 'merchant_before_mini_cart_contents', |
| 424 |
'woocommerce_widget_shopping_cart_before_buttons' => 'merchant_widget_shopping_cart_before_buttons', |
| 425 |
'woocommerce_widget_shopping_cart_after_buttons' => 'merchant_widget_shopping_cart_after_buttons', |
| 426 |
); |
| 427 |
|
| 428 |
// Check and update side cart placement if the current setting has a mapped new value |
| 429 |
if ( isset( $placement_mapping[ $side_cart_placement ] ) ) { |
| 430 |
Merchant_Admin_Options::set( $fsb_module_id, 'side_cart_placement', sanitize_text_field( $placement_mapping[ $side_cart_placement ] ) ); |
| 431 |
} |
| 432 |
} |
| 433 |
|
| 434 |
// Delete FMC Module's Enabled/Disabled data from DB |
| 435 |
$modules = get_option( Merchant_Modules::$option, array() ); |
| 436 |
if ( isset( $modules[ $fmc_module_id ] ) ) { |
| 437 |
unset( $modules[ $fmc_module_id ] ); |
| 438 |
update_option( Merchant_Modules::$option, $modules ); |
| 439 |
} |
| 440 |
|
| 441 |
// Delete FMC Module's settings information from DB |
| 442 |
$options = get_option( 'merchant', array() ); |
| 443 |
if ( isset( $options[ $fmc_module_id ] ) ) { |
| 444 |
unset( $options[ $fmc_module_id ] ); |
| 445 |
update_option( 'merchant', $options ); |
| 446 |
} |
| 447 |
|
| 448 |
// Track Migration to do the action once only. |
| 449 |
update_option( 'merchant_floating_mini_cart_merged_with_side_cart', true ); |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
// Initialize the module. |
| 454 |
add_action( 'init', function () { |
| 455 |
Merchant_Modules::create_module( new Merchant_Side_Cart() ); |
| 456 |
} ); |
| 457 |
|