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

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

339 lines 14.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Size Chart
5 *
6 * @package Merchant
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly
11 }
12
13 /**
14 * Size Chart class.
15 *
16 */
17 class Merchant_Size_Chart extends Merchant_Add_Module {
18
19 /**
20 * Module ID.
21 *
22 */
23 const MODULE_ID = 'size-chart';
24
25 /**
26 * Is module preview.
27 *
28 */
29 public static $is_module_preview = false;
30
31 /**
32 * Initialize the module's option group definitions.
33 *
34 * @return array<int, array<string, mixed>> Array of option group arrays.
35 */
36 protected function init_option_groups() {
37 return require MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
38 }
39
40 /**
41 * Constructor.
42 *
43 */
44 public function __construct() {
45 // Module id.
46 $this->module_id = self::MODULE_ID;
47
48 // WooCommerce only.
49 $this->wc_only = true;
50
51 // Parent construct.
52 parent::__construct();
53
54 // Module section.
55 $this->module_section = 'improve-experience';
56
57 // Module default settings.
58 $this->module_default_settings = array(
59 'global_size_chart' => '',
60 'text' => __( 'Size Chart', 'merchant' ),
61 'icon' => 'icon-size-chart',
62 );
63
64 // Module data.
65 $this->module_data = Merchant_Admin_Modules::$modules_data[ self::MODULE_ID ];
66
67 // AI prompt examples.
68 $this->ai_examples = array(
69 'blurb' => esc_html__( 'See what AI can do for your size charts, from building a new one to assigning it to the right products and categories.', 'merchant' ),
70 'prompts' => array(
71 esc_html__( 'Explore the abilities WPVibe gives you access to, then create a Footwear size chart with US, EU, and UK columns covering shoe sizes 5 through 12', 'merchant' ),
72 esc_html__( 'Check what abilities you have available through WPVibe, then add a Women\'s Sizing tab to the Footwear size chart and a short fit-guide description below it', 'merchant' ),
73 esc_html__( 'Look at your available WPVibe abilities, then assign the Footwear size chart to every product in the Shoes category', 'merchant' ),
74 esc_html__( 'See what abilities WPVibe exposes, then change the size chart button label from \'Size Chart\' to \'Find My Fit\'', 'merchant' ),
75 ),
76 );
77
78 // Module options path.
79 $this->module_options_path = MERCHANT_DIR . 'inc/modules/' . self::MODULE_ID . '/admin/options.php';
80
81 // Is module preview page.
82 if ( is_admin() && parent::is_module_settings_page() ) {
83 self::$is_module_preview = true;
84
85 // Enqueue admin styles.
86 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_css' ) );
87
88 // Enqueue admin scripts.
89 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
90
91 // Render module essencial instructions before the module page body content.
92 add_action( 'merchant_admin_after_module_page_page_header', array( $this, 'admin_module_essencial_instructions' ) );
93
94 // Admin preview box.
95 add_filter( 'merchant_module_preview', array( $this, 'render_admin_preview' ), 10, 2 );
96
97 // Custom CSS.
98 // The custom CSS should be added here as well due to ensure preview box works properly.
99 add_filter( 'merchant_custom_css', array( $this, 'admin_custom_css' ) );
100 }
101
102 if ( Merchant_Modules::is_module_active( self::MODULE_ID ) && is_admin() ) {
103 // Init translations.
104 $this->init_translations();
105 }
106 }
107
108 /**
109 * Init translations.
110 *
111 * @return void
112 */
113 public function init_translations() {
114 $settings = $this->get_module_settings();
115 if ( ! empty( $settings['text'] ) ) {
116 Merchant_Translator::register_string( $settings['text'], esc_html__( 'Size chart: label text', 'merchant' ) );
117 }
118 }
119
120 /**
121 * Admin enqueue CSS.
122 *
123 * @return void
124 */
125 public function admin_enqueue_css() {
126 if ( parent::is_module_settings_page() ) {
127 wp_enqueue_style( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/size-chart.min.css', array(), MERCHANT_VERSION );
128 wp_enqueue_style( 'merchant-admin-' . self::MODULE_ID, MERCHANT_URI . 'assets/css/modules/' . self::MODULE_ID . '/admin/preview.min.css', array(), MERCHANT_VERSION );
129 }
130 }
131
132 /**
133 * Admin Enqueue scripts.
134 *
135 * @return void
136 */
137 public function admin_enqueue_scripts() {
138 // Register and enqueue the main module script.
139 wp_enqueue_script( 'merchant-' . self::MODULE_ID, MERCHANT_URI . 'assets/js/modules/' . self::MODULE_ID . '/size-chart.min.js', array(), MERCHANT_VERSION, true );
140 }
141
142 /**
143 * Render module essencial instructions.
144 *
145 * @return void
146 */
147 public function admin_module_essencial_instructions() { ?>
148 <div class="merchant-module-page-settings">
149 <div class="merchant-module-page-setting-box merchant-module-page-setting-box-style-2">
150 <div class="merchant-module-page-setting-fields">
151 <div class="merchant-module-page-setting-field merchant-module-page-setting-field-content">
152 <div class="merchant-module-page-setting-field-inner">
153 <div class="merchant-tag-pre-orders">
154 <i class="dashicons dashicons-info"></i>
155 <p><?php echo esc_html__( 'You can have as many size charts you want and either specify in which product you want to add them or simply enable one globally to be displayed in all products. But if you want to display different size charts for each product, that\'s possible from admin product edit page.',
156 'merchant' ); ?><?php printf( '<a href="%s" target="_blank">%s</a>',
157 esc_url( admin_url( 'edit.php?post_type=product' ) ),
158 esc_html__( 'View All Products', 'merchant' ) ); ?></p>
159 </div>
160 </div>
161 </div>
162 </div>
163 </div>
164 </div>
165
166 <?php
167 }
168
169 /**
170 * Render admin preview
171 *
172 * @param Merchant_Admin_Preview $preview
173 * @param string $module
174 *
175 * @return Merchant_Admin_Preview
176 */
177 public function render_admin_preview( $preview, $module ) {
178 if ( self::MODULE_ID === $module ) {
179 ob_start();
180 self::admin_preview_content();
181 $content = ob_get_clean();
182
183 // HTML.
184 $preview->set_html( $content );
185
186 // Label Text.
187 $preview->set_text( 'text', '.merchant-product-size-chart-button span' );
188
189 // Icon.
190 $preview->set_svg_icon( 'icon', '.size-chart-icon' );
191 }
192
193 return $preview;
194 }
195
196 /**
197 * Admin preview content.
198 *
199 * @return void
200 */
201 public function admin_preview_content() {
202 $settings = $this->get_module_settings();
203
204 ?>
205
206 <div class="mrc-preview-single-product-elements">
207 <div class="mrc-preview-left-column">
208 <div class="mrc-preview-product-image-wrapper">
209 <div class="mrc-preview-product-image"></div>
210 <div class="mrc-preview-product-image-thumbs">
211 <div class="mrc-preview-product-image-thumb"></div>
212 <div class="mrc-preview-product-image-thumb"></div>
213 <div class="mrc-preview-product-image-thumb"></div>
214 </div>
215 </div>
216 </div>
217 <div class="mrc-preview-right-column">
218 <div class="mrc-preview-text-placeholder"></div>
219 <div class="mrc-preview-text-placeholder mrc-mw-70"></div>
220 <div class="mrc-preview-text-placeholder mrc-mw-30"></div>
221 <div class="merchant-product-size-chart">
222 <div class="merchant-product-size-chart-button">
223 <a href="#">
224 <div class="size-chart-icon">
225 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( $settings['icon'] ), merchant_kses_allowed_tags( array(), false ) ); ?>
226 </div>
227 <span><?php echo esc_html( $settings['text'] ); ?></span>
228 </a>
229 </div>
230 <div class="merchant-product-size-chart-modal">
231 <div class="merchant-product-size-chart-modal-inner">
232 <div class="merchant-product-size-chart-modal-close">
233 <?php echo wp_kses( Merchant_SVG_Icons::get_svg_icon( 'icon-close' ), merchant_kses_allowed_tags( array(), false ) ); ?>
234 </div>
235 <div class="merchant-product-size-chart-modal-title">
236 <?php echo esc_html__( 'Size Chart Modal Title', 'merchant' ); ?>
237 </div>
238 <div class="merchant-product-size-chart-modal-tables">
239 <table class="merchant-product-size-chart-modal-table active">
240 <thead>
241 <tr>
242 <th><?php echo esc_html__( 'US', 'merchant' ); ?></th>
243 <th><?php echo esc_html__( 'EU', 'merchant' ); ?></th>
244 <th><?php echo esc_html__( 'UK', 'merchant' ); ?></th>
245 </tr>
246 </thead>
247 <tbody>
248 <tr>
249 <td>3</td>
250 <td>35</td>
251 <td>5</td>
252 </tr>
253 <tr>
254 <td>4</td>
255 <td>36</td>
256 <td>6</td>
257 </tr>
258 <tr>
259 <td>5</td>
260 <td>37</td>
261 <td>7</td>
262 </tr>
263 <tr>
264 <td>6</td>
265 <td>38</td>
266 <td>8</td>
267 </tr>
268 <tr>
269 <td>7</td>
270 <td>39</td>
271 <td>9</td>
272 </tr>
273 </tbody>
274 </table>
275 </div>
276 <div class="merchant-product-size-chart-modal-content">
277 <p>Lorem ipsum dolor sit a met, dont dolor sit a la quat. </p>
278 </div>
279 </div>
280 </div>
281 </div>
282 <div class="mrc-preview-addtocart-placeholder"></div>
283 </div>
284 </div>
285
286 <?php
287 }
288
289 /**
290 * Custom CSS.
291 *
292 * @return string
293 */
294 public function get_module_custom_css() {
295 $css = '';
296
297 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-size', 24, '.merchant-product-size-chart', '--mrc-sc-icon-size', 'px' );
298 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'title-text-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-title-text-color' );
299 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'title-text-color-hover', '#757575', '.merchant-product-size-chart', '--mrc-sc-title-text-color-hover' );
300 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-icon-color' );
301 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'icon-color-hover', '#757575', '.merchant-product-size-chart', '--mrc-sc-icon-color-hover' );
302
303 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'popup-width', 750, '.merchant-product-size-chart', '--mrc-sc-popup-width', 'px' );
304 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'background-color', '#f2f2f2', '.merchant-product-size-chart', '--mrc-sc-background-color' );
305 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'close-icon-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-close-icon-color' );
306 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'close-icon-color-hover', '#757575', '.merchant-product-size-chart', '--mrc-sc-close-icon-color-hover' );
307 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'title-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-title-color' );
308 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'tabs-color', '#757575', '.merchant-product-size-chart', '--mrc-sc-tabs-color' );
309 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'tabs-color-active', '#212121', '.merchant-product-size-chart', '--mrc-sc-tabs-color-active' );
310 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'table-headings-background-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-table-headings-background-color' );
311 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'table-headings-text-color', '#ffffff', '.merchant-product-size-chart', '--mrc-sc-table-headings-text-color' );
312 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'table-body-background-color', '#ffffff', '.merchant-product-size-chart', '--mrc-sc-table-body-background-color' );
313 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'table-body-text-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-table-body-text-color' );
314 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'description-text-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-description-text-color' );
315 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'description-link-color', '#212121', '.merchant-product-size-chart', '--mrc-sc-description-link-color' );
316 $css .= Merchant_Custom_CSS::get_variable_css( self::MODULE_ID, 'description-link-color-hover', '#757575', '.merchant-product-size-chart', '--mrc-sc-description-link-color-hover' );
317
318 return $css;
319 }
320
321 /**
322 * Admin custom CSS.
323 *
324 * @param string $css The custom CSS.
325 *
326 * @return string $css The custom CSS.
327 */
328 public function admin_custom_css( $css ) {
329 $css .= $this->get_module_custom_css();
330
331 return $css;
332 }
333 }
334
335 // Initialize the module.
336 add_action( 'init', function () {
337 Merchant_Modules::create_module( new Merchant_Size_Chart() );
338 } );
339