| 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 |
* Is module preview. |
| 26 |
* |
| 27 |
*/ |
| 28 |
public static $is_module_preview = false; |
| 29 |
|
| 30 |
/** |
| 31 |
* Constructor. |
| 32 |
* |
| 33 |
*/ |
| 34 |
public function __construct() { |
| 35 |
// Module id. |
| 36 |
$this->module_id = self::MODULE_ID; |
| 37 |
|
| 38 |
// WooCommerce only. |
| 39 |
$this->wc_only = true; |
| 40 |
|
| 41 |
// Parent construct. |
| 42 |
parent::__construct(); |
| 43 |
|
| 44 |
// Module default settings. |
| 45 |
$this->module_default_settings = array( |
| 46 |
'show_after_add_to_cart' => 1, |
| 47 |
'show_after_add_to_cart_single_product' => 0, |
| 48 |
'show_on_cart_url_click' => 1 |
| 49 |
); |
| 50 |
|
| 51 |
// Module data. |
| 52 |
$this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ]; |
| 53 |
$this->module_data['preview_url'] = $this->set_module_preview_url( array( 'type' => 'shop' ) ); |
| 54 |
|
| 55 |
// Module section. |
| 56 |
$this->module_section = $this->module_data['section']; |
| 57 |
|
| 58 |
// Module options path. |
| 59 |
$this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php'; |
| 60 |
|
| 61 |
// Is module preview page. |
| 62 |
if ( is_admin() && parent::is_module_settings_page() ) { |
| 63 |
self::$is_module_preview = true; |
| 64 |
|
| 65 |
// Enqueue admin styles. |
| 66 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) ); |
| 67 |
|
| 68 |
// Enqueue admin scripts. |
| 69 |
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 70 |
|
| 71 |
// Admin preview box. |
| 72 |
add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 ); |
| 73 |
|
| 74 |
// Custom CSS. |
| 75 |
add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Admin enqueue CSS. |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function admin_enqueue_css() { |
| 85 |
if ( $this->is_module_settings_page() ) { |
| 86 |
wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . Merchant_Floating_Mini_Cart::MODULE_ID . '/floating-mini-cart.min.css', [], MERCHANT_VERSION ); |
| 87 |
wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, |
| 88 |
MERCHANT_URI . 'assets/css/modules/' . Merchant_Floating_Mini_Cart::MODULE_ID . '/admin/preview.min.css', |
| 89 |
array(), |
| 90 |
MERCHANT_VERSION ); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Admin Enqueue scripts. |
| 96 |
* |
| 97 |
* @return void |
| 98 |
*/ |
| 99 |
public function admin_enqueue_scripts() { |
| 100 |
// Register and enqueue the main module script. |
| 101 |
wp_enqueue_script( 'merchant-' . self::MODULE_ID, |
| 102 |
MERCHANT_URI . 'assets/js/modules/' . Merchant_Floating_Mini_Cart::MODULE_ID . '/floating-mini-cart.min.js', |
| 103 |
array(), |
| 104 |
MERCHANT_VERSION, |
| 105 |
true ); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
/** |
| 110 |
* Render admin preview |
| 111 |
* |
| 112 |
* @param Merchant_Admin_Preview $preview |
| 113 |
* @param string $module |
| 114 |
* |
| 115 |
* @return Merchant_Admin_Preview |
| 116 |
*/ |
| 117 |
public function render_admin_preview( $preview, $module ) { |
| 118 |
if ( $module === self::MODULE_ID ) { |
| 119 |
ob_start(); |
| 120 |
self::admin_preview_content(); |
| 121 |
$content = ob_get_clean(); |
| 122 |
|
| 123 |
// HTML. |
| 124 |
$preview->set_html( $content ); |
| 125 |
} |
| 126 |
|
| 127 |
return $preview; |
| 128 |
} |
| 129 |
|
| 130 |
/** |
| 131 |
* Admin preview content. |
| 132 |
* |
| 133 |
* @return void |
| 134 |
*/ |
| 135 |
public function admin_preview_content() { |
| 136 |
?> |
| 137 |
|
| 138 |
<div class="mrc-preview-single-product-elements"> |
| 139 |
<div class="mrc-preview-left-column"> |
| 140 |
<div class="mrc-preview-product-image-wrapper"> |
| 141 |
<div class="mrc-preview-product-image"></div> |
| 142 |
<div class="mrc-preview-product-image-thumbs"> |
| 143 |
<div class="mrc-preview-product-image-thumb"></div> |
| 144 |
<div class="mrc-preview-product-image-thumb"></div> |
| 145 |
<div class="mrc-preview-product-image-thumb"></div> |
| 146 |
</div> |
| 147 |
</div> |
| 148 |
</div> |
| 149 |
<div class="mrc-preview-right-column"> |
| 150 |
<div class="mrc-preview-text-placeholder"></div> |
| 151 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 152 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 153 |
<div class="mrc-preview-text-placeholder"></div> |
| 154 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 155 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 156 |
<div class="mrc-preview-text-placeholder"></div> |
| 157 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 158 |
<div class="mrc-preview-text-placeholder mrc-mw-30"></div> |
| 159 |
<div class="mrc-preview-text-placeholder"></div> |
| 160 |
<div class="mrc-preview-text-placeholder mrc-mw-70"></div> |
| 161 |
<div class="mrc-preview-addtocart-placeholder"></div> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
|
| 165 |
<div class="merchant-floating-side-mini-cart-show"> |
| 166 |
<div class="merchant-floating-side-mini-cart-overlay merchant-floating-side-mini-cart-toggle"></div> |
| 167 |
<div class="merchant-floating-side-mini-cart"> |
| 168 |
<div class="merchant-floating-side-mini-cart-body"> |
| 169 |
<a href="#" class="merchant-floating-side-mini-cart-close-button merchant-floating-side-mini-cart-toggle" |
| 170 |
title="<?php echo esc_attr__( 'Close the side mini cart', 'merchant' ); ?>"> |
| 171 |
<?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( 'icon-cancel' ), merchant_kses_allowed_tags( [], false ) ); ?> |
| 172 |
</a> |
| 173 |
|
| 174 |
<div class="merchant-floating-side-mini-cart-widget"> |
| 175 |
<div class="merchant-floating-side-mini-cart-widget-title"><?php echo esc_html__( 'Your Cart', 'merchant' ); ?></div> |
| 176 |
<div class="widget_shopping_cart_content"> |
| 177 |
<ul class="woocommerce-mini-cart cart_list product_list_widget"> |
| 178 |
<li class="woocommerce-mini-cart-item mini_cart_item"> |
| 179 |
<a href="#" class="remove remove_from_cart_button">×</a> |
| 180 |
<a href="#"> |
| 181 |
<span class="mrc-product-image"></span> |
| 182 |
<?php echo esc_html__( 'Product Sample Title', 'merchant' ); ?> |
| 183 |
</a> |
| 184 |
<span class="quantity">1 × |
| 185 |
<span class="woocommerce-Price-amount amount"> |
| 186 |
<bdi><span class="woocommerce-Price-currencySymbol">$</span>12.00 </bdi> |
| 187 |
</span> |
| 188 |
</span> |
| 189 |
</li> |
| 190 |
<li class="woocommerce-mini-cart-item mini_cart_item"> |
| 191 |
<a href="#" class="remove remove_from_cart_button">×</a> |
| 192 |
<a href="#"> |
| 193 |
<span class="mrc-product-image"></span> |
| 194 |
<?php echo esc_html__( 'Product Sample Title', 'merchant' ); ?> |
| 195 |
</a> |
| 196 |
<span class="quantity">1 × |
| 197 |
<span class="woocommerce-Price-amount amount"> |
| 198 |
<bdi><span class="woocommerce-Price-currencySymbol">$</span>12.00 </bdi> |
| 199 |
</span> |
| 200 |
</span> |
| 201 |
</li> |
| 202 |
</ul> |
| 203 |
|
| 204 |
<p class="woocommerce-mini-cart__total total"> |
| 205 |
<strong><?php echo esc_html__( 'Subtotal:', 'merchant' ); ?></strong> |
| 206 |
<span class="woocommerce-Price-amount amount"> |
| 207 |
<bdi><span class="woocommerce-Price-currencySymbol">$</span>12.00 </bdi> |
| 208 |
</span> |
| 209 |
</p> |
| 210 |
<p class="woocommerce-mini-cart__buttons buttons"> |
| 211 |
<a href="#" class="button wc-forward"><?php echo esc_html__( 'View cart:', 'merchant' ); ?></a> |
| 212 |
<a href="#" class="button checkout wc-forward"><?php echo esc_html__( 'Checkout:', 'merchant' ); ?></a> |
| 213 |
</p> |
| 214 |
</div> |
| 215 |
</div> |
| 216 |
</div> |
| 217 |
</div> |
| 218 |
</div> |
| 219 |
|
| 220 |
<?php |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Admin custom CSS. |
| 225 |
* |
| 226 |
* @param string $css The custom CSS. |
| 227 |
* |
| 228 |
* @return string $css The custom CSS. |
| 229 |
*/ |
| 230 |
public function admin_custom_css( $css ) { |
| 231 |
$css .= Merchant_Floating_Mini_Cart::get_module_custom_css(); |
| 232 |
|
| 233 |
return $css; |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
// Initialize the module. |
| 238 |
add_action( 'init', function () { |
| 239 |
Merchant_Modules::create_module( new Merchant_Side_Cart() ); |
| 240 |
} ); |
| 241 |
|