PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.2.8
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.2.8
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 / wishlist / class-wishlist.php

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

267 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Wishlist.
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Wishlist class.
15 *
16 */
17 class Merchant_Wishlist extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'wishlist';
24
25 /**
26 * Is module preview.
27 *
28 */
29 public static $is_module_preview = false;
30
31 /**
32 * Module settings.
33 *
34 */
35 public static $module_settings = array();
36
37 /**
38 * Constructor.
39 *
40 */
41 public function __construct() {
42
43 // Module id.
44 $this->module_id = self::MODULE_ID;
45
46 // WooCommerce only.
47 $this->wc_only = true;
48
49 // Parent construct.
50 parent::__construct();
51
52 // Module section.
53 $this->module_section = 'improve-experience';
54
55 // Module default settings.
56 $this->module_default_settings = array(
57 'display_on_shop_archive' => 1,
58 'display_on_single_product' => 1,
59 'display_on_cart_page' => false,
60 'posts_per_page' => 6,
61 'cart_page_title' => esc_html__( 'Your wishlist items', 'merchant' ),
62 'cart_page_title_tag' => 'h2',
63 'button_icon' => 'heart1',
64 'button_position_top' => 8,
65 'button_position_left' => 85,
66 'tooltip' => 1,
67 'tooltip_text' => esc_html__( 'Add To Wishlist', 'merchant' ),
68 'tooltip_text_after' => esc_html__( 'Added To Wishlist', 'merchant' ),
69 'tooltip_border_radius' => 4,
70 'hide_page_title' => 0,
71 'enable_sharing' => 1,
72 'sharing_links' => array(
73 array(
74 'layout' => 'social',
75 'social_network' => 'facebook',
76 ),
77 array(
78 'layout' => 'social',
79 'social_network' => 'twitter',
80 ),
81 array(
82 'layout' => 'social',
83 'social_network' => 'linkedin',
84 ),
85 ),
86 'display_copy_to_clipboard' => 1,
87 );
88
89 // Module data.
90 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
91
92 // Module options path.
93 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
94
95 // Store module handled (with defaults) module settings into a static variable.
96 self::$module_settings = $this->get_module_settings();
97
98 // Is module preview page.
99 if ( is_admin() && parent::is_module_settings_page() ) {
100 self::$is_module_preview = true;
101
102 // Enqueue admin styles.
103 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
104
105 // Admin preview box.
106 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
107
108 // Custom CSS.
109 // The custom CSS should be added here as well due to ensure preview box works properly.
110 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
111
112 }
113 }
114 /**
115 * Admin enqueue CSS.
116 *
117 * @return void
118 */
119 public function admin_enqueue_css() {
120 if ( parent::is_module_settings_page() ) {
121 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/wishlist-button.min.css', array(), MERCHANT_VERSION );
122 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
123 }
124 }
125
126 /**
127 * Render admin preview
128 *
129 * @param Merchant_Admin_Preview $preview
130 * @param string $module
131 *
132 * @return Merchant_Admin_Preview
133 */
134 public function render_admin_preview( $preview, $module ) {
135 if ( self::MODULE_ID === $module ) {
136 ob_start();
137 $this->admin_preview_content();
138 $content = ob_get_clean();
139
140 // HTML.
141 $preview->set_html( $content );
142
143 // Select Icon.
144 $preview->set_svg_icon( 'button_icon', '.merchant-wishlist-button' );
145
146 // Dislplay Tooltip.
147 $preview->set_class( 'tooltip', '.merchant-wishlist-button', array(), 'merchant-wishlist-button-tooltip' );
148
149 // Tooltip Text.
150 $preview->set_attribute( 'tooltip_text', '.merchant-wishlist-button', 'data-merchant-wishlist-tooltip' );
151
152 }
153
154 return $preview;
155 }
156
157 /**
158 * Admin preview content.
159 *
160 * @return void
161 */
162 public function admin_preview_content() {
163 $settings = self::$module_settings;
164
165 ?>
166
167 <div class="merchant-wishlist-product-preview">
168 <div class="image-wrapper">
169 <a href="#" class="merchant-wishlist-button<?php echo ( $settings[ 'tooltip' ] ) ? ' merchant-wishlist-button-tooltip' : ''; ?>" data-type="add" data-wishlist-link="#" data-merchant-wishlist-tooltip="<?php echo esc_attr( $settings[ 'tooltip_text' ] ); ?>">
170 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( $settings[ 'button_icon' ] ), merchant_kses_allowed_tags( array(), false ) ); ?>
171 </a>
172 </div>
173 <h3><?php echo esc_html__( 'Product Title', 'merchant' ); ?></h3>
174 <p><?php echo esc_html__( 'Product description normally goes here.', 'merchant' ); ?></p>
175 </div>
176
177 <?php
178 }
179
180 /**
181 * Custom CSS.
182 *
183 * @return string $css The custom CSS.
184 */
185 public function get_module_custom_css() {
186 $css = '';
187
188 /**
189 * Add To Wishlist Button Settings
190 *
191 */
192
193 // Button position top.
194 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'button_position_top', 20, '.merchant-wishlist-button', '--mrc-wl-button-position-top', 'px' );
195
196 // Button position left.
197 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'button_position_left', 20, '.merchant-wishlist-button', '--mrc-wl-button-position-left', 'px' );
198
199 // Icon stroke color.
200 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_stroke_color', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-icon-stroke-color' );
201 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_stroke_color_hover', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-icon-stroke-color-hover' );
202
203 // Icon fill color.
204 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_fill_color', 'transparent', '.merchant-wishlist-button', '--mrc-wl-button-icon-fill-color' );
205 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_fill_color_hover', '#f04c4c', '.merchant-wishlist-button', '--mrc-wl-button-icon-fill-color-hover' );
206
207 // Tooltip text color.
208 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_text_color', '#FFF', '.merchant-wishlist-button', '--mrc-wl-button-tooltip-text-color' );
209
210 // Tooltip background color.
211 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_background_color', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-tooltip-background-color' );
212
213 // Tooltip border radius.
214 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_border_radius', 4, '.merchant-wishlist-button', '--mrc-wl-button-tooltip-border-radius', 'px' );
215
216 /**
217 * Wishlist Page Template Settings
218 *
219 */
220
221 // Table heading background color.
222 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_heading_background_color', '#f8f8f8', '.is-merchant-wishlist-page', '--mrc-wl-table-heading-background-color' );
223
224 // Table body background color.
225 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_body_background_color', '#fdfdfd', '.is-merchant-wishlist-page', '--mrc-wl-table-body-background-color' );
226
227 // Table text color.
228 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_text_color', '#777', '.is-merchant-wishlist-page', '--mrc-wl-table-text-color' );
229
230 // Table links color.
231 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_links_color', '#212121', '.is-merchant-wishlist-page', '--mrc-wl-table-links-color' );
232
233 // Table links color (hover).
234 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_links_color_hover', '#757575', '.is-merchant-wishlist-page', '--mrc-wl-table-links-color-hover' );
235
236 // Buttons color.
237 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_color', '#FFF', '.is-merchant-wishlist-page', '--mrc-wl-buttons-color' );
238
239 // Buttons color (hover).
240 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_color_hover', '#FFF', '.is-merchant-wishlist-page', '--mrc-wl-buttons-color-hover' );
241
242 // Buttons background color.
243 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_background_color', '#212121', '.is-merchant-wishlist-page', '--mrc-wl-buttons-bg-color' );
244
245 // Buttons color (hover).
246 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_background_color_hover', '#757575', '.is-merchant-wishlist-page', '--mrc-wl-buttons-bg-color-hover' );
247
248 return $css;
249 }
250
251 /**
252 * Admin custom CSS.
253 *
254 * @param string $css The custom CSS.
255 * @return string $css The custom CSS.
256 */
257 public function admin_custom_css( $css ) {
258 $css .= $this->get_module_custom_css();
259
260 return $css;
261 }
262 }
263
264 // Initialize the module.
265 add_action( 'init', function() {
266 Merchant_Modules::create_module(new Merchant_Wishlist());
267 } );