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

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