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

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