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

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