PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.2
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 1.10.2, at inc/modules/wishlist/class-wishlist.php

271 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 'button_icon' => 'heart1',
60 'button_position_top' => 8,
61 'button_position_left' => 85,
62 'tooltip' => 1,
63 'tooltip_text' => __( 'Add To Wishlist', 'merchant' ),
64 'tooltip_text_after' => __( 'Added To Wishlist', 'merchant' ),
65 'tooltip_border_radius' => 4,
66 'hide_page_title' => 0,
67 'enable_sharing' => 1,
68 'sharing_links' => array(
69 array(
70 'layout' => 'social',
71 'social_network' => 'facebook',
72 ),
73 array(
74 'layout' => 'social',
75 'social_network' => 'twitter',
76 ),
77 array(
78 'layout' => 'social',
79 'social_network' => 'linkedin',
80 ),
81 ),
82 'display_copy_to_clipboard' => 1,
83 );
84
85 // Mount preview url.
86 $preview_url = site_url( '/' );
87
88 if ( function_exists( 'wc_get_page_id' ) ) {
89 $preview_url = get_permalink( wc_get_page_id( 'shop' ) );
90 }
91
92 // Module data.
93 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
94 $this->module_data[ 'preview_url' ] = $preview_url;
95
96 // Module options path.
97 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
98
99 // Store module handled (with defaults) module settings into a static variable.
100 self::$module_settings = $this->get_module_settings();
101
102 // Is module preview page.
103 if ( is_admin() && parent::is_module_settings_page() ) {
104 self::$is_module_preview = true;
105
106 // Enqueue admin styles.
107 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
108
109 // Admin preview box.
110 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
111
112 // Custom CSS.
113 // The custom CSS should be added here as well due to ensure preview box works properly.
114 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
115
116 }
117 }
118 /**
119 * Admin enqueue CSS.
120 *
121 * @return void
122 */
123 public function admin_enqueue_css() {
124 if ( parent::is_module_settings_page() ) {
125 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/wishlist-button.min.css', array(), MERCHANT_VERSION );
126 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
127 }
128 }
129
130 /**
131 * Render admin preview
132 *
133 * @param Merchant_Admin_Preview $preview
134 * @param string $module
135 *
136 * @return Merchant_Admin_Preview
137 */
138 public function render_admin_preview( $preview, $module ) {
139 if ( self::MODULE_ID === $module ) {
140 ob_start();
141 $this->admin_preview_content();
142 $content = ob_get_clean();
143
144 // HTML.
145 $preview->set_html( $content );
146
147 // Select Icon.
148 $preview->set_svg_icon( 'button_icon', '.merchant-wishlist-button' );
149
150 // Dislplay Tooltip.
151 $preview->set_class( 'tooltip', '.merchant-wishlist-button', array(), 'merchant-wishlist-button-tooltip' );
152
153 // Tooltip Text.
154 $preview->set_attribute( 'tooltip_text', '.merchant-wishlist-button', 'data-merchant-wishlist-tooltip' );
155
156 }
157
158 return $preview;
159 }
160
161 /**
162 * Admin preview content.
163 *
164 * @return void
165 */
166 public function admin_preview_content() {
167 $settings = self::$module_settings;
168
169 ?>
170
171 <div class="merchant-wishlist-product-preview">
172 <div class="image-wrapper">
173 <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' ] ); ?>">
174 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( $settings[ 'button_icon' ] ), merchant_kses_allowed_tags( array(), false ) ); ?>
175 </a>
176 </div>
177 <h3><?php echo esc_html__( 'Product Title', 'merchant' ); ?></h3>
178 <p><?php echo esc_html__( 'Product description normally goes here.', 'merchant' ); ?></p>
179 </div>
180
181 <?php
182 }
183
184 /**
185 * Custom CSS.
186 *
187 * @return string $css The custom CSS.
188 */
189 public function get_module_custom_css() {
190 $css = '';
191
192 /**
193 * Add To Wishlist Button Settings
194 *
195 */
196
197 // Button position top.
198 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'button_position_top', 20, '.merchant-wishlist-button', '--mrc-wl-button-position-top', 'px' );
199
200 // Button position left.
201 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'button_position_left', 20, '.merchant-wishlist-button', '--mrc-wl-button-position-left', 'px' );
202
203 // Icon stroke color.
204 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_stroke_color', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-icon-stroke-color' );
205 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_stroke_color_hover', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-icon-stroke-color-hover' );
206
207 // Icon fill color.
208 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_fill_color', 'transparent', '.merchant-wishlist-button', '--mrc-wl-button-icon-fill-color' );
209 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'icon_fill_color_hover', '#f04c4c', '.merchant-wishlist-button', '--mrc-wl-button-icon-fill-color-hover' );
210
211 // Tooltip text color.
212 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_text_color', '#FFF', '.merchant-wishlist-button', '--mrc-wl-button-tooltip-text-color' );
213
214 // Tooltip background color.
215 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_background_color', '#212121', '.merchant-wishlist-button', '--mrc-wl-button-tooltip-background-color' );
216
217 // Tooltip border radius.
218 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'tooltip_border_radius', 4, '.merchant-wishlist-button', '--mrc-wl-button-tooltip-border-radius', 'px' );
219
220 /**
221 * Wishlist Page Template Settings
222 *
223 */
224
225 // Table heading background color.
226 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_heading_background_color', '#f8f8f8', '.is-merchant-wishlist-page', '--mrc-wl-table-heading-background-color' );
227
228 // Table body background color.
229 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_body_background_color', '#fdfdfd', '.is-merchant-wishlist-page', '--mrc-wl-table-body-background-color' );
230
231 // Table text color.
232 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_text_color', '#777', '.is-merchant-wishlist-page', '--mrc-wl-table-text-color' );
233
234 // Table links color.
235 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_links_color', '#212121', '.is-merchant-wishlist-page', '--mrc-wl-table-links-color' );
236
237 // Table links color (hover).
238 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'table_links_color_hover', '#757575', '.is-merchant-wishlist-page', '--mrc-wl-table-links-color-hover' );
239
240 // Buttons color.
241 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_color', '#FFF', '.is-merchant-wishlist-page', '--mrc-wl-buttons-color' );
242
243 // Buttons color (hover).
244 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_color_hover', '#FFF', '.is-merchant-wishlist-page', '--mrc-wl-buttons-color-hover' );
245
246 // Buttons background color.
247 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_background_color', '#212121', '.is-merchant-wishlist-page', '--mrc-wl-buttons-bg-color' );
248
249 // Buttons color (hover).
250 $css .= Merchant_Custom_CSS::get_variable_css( 'wishlist', 'buttons_background_color_hover', '#757575', '.is-merchant-wishlist-page', '--mrc-wl-buttons-bg-color-hover' );
251
252 return $css;
253 }
254
255 /**
256 * Admin custom CSS.
257 *
258 * @param string $css The custom CSS.
259 * @return string $css The custom CSS.
260 */
261 public function admin_custom_css( $css ) {
262 $css .= $this->get_module_custom_css();
263
264 return $css;
265 }
266 }
267
268 // Initialize the module.
269 add_action( 'init', function() {
270 Merchant_Modules::create_module(new Merchant_Wishlist());
271 } );