PluginProbe
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder / 3.0.4
Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder v3.0.4
3.1.4 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.0.7 3.0.5 3.0.4 3.0.3 3.0.2 trunk 1.5.0 1.5.1 1.5.2 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 All 93 releases
ultimate-store-kit / includes / helper.php

helper.php in Ultimate Store Kit – Store Builder Addons for Elementor, WooCommerce Store Builder, EDD Store Builder 3.0.4, at includes/helper.php

1,477 lines 40.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use UltimateStoreKit\Ultimate_Store_Kit_Loader;
4 use Elementor\Plugin;
5
6 /**
7 * You can easily add white label branding for for extended license or multi site license.
8 * Don't try for regular license otherwise your license will be invalid.
9 * return white label
10 */
11
12 if (! defined('BDTUSK')) {
13 define('BDTUSK', '');
14 }
15
16 //Add prefix for all widgets <span class="usk-widget-badge"></span>
17 if (! defined('BDTUSK_CP')) {
18 define('BDTUSK_CP', '<span class="usk-widget-badge"></span>');
19 }
20
21 //Add prefix for all widgets <span class="usk-widget-badge"></span>
22 if (! defined('BDTUSK_NC')) {
23 define('BDTUSK_NC', '<span class="usk-new-control"></span>');
24 }
25
26 // if you have any custom style
27 if (! defined('BDTUSK_SLUG')) {
28 define('BDTUSK_SLUG', 'ultimate-store-kit');
29 }
30
31 // set your own alias
32 if (! defined('BDTUSK_VER')) {
33 define('BDTUSK_VER', 'Ultimate Store Kit');
34 }
35
36 // Set your own name for plugin
37
38 if (! defined('BDTUSK_NAME')) {
39 define('BDTUSK_NAME', 'Ultimate Store Kit');
40 }
41
42 if (_is_usk_pro_activated()) {
43 if (! defined('BDTUSK_PC')) {
44 define('BDTUSK_PC', '');
45 } // pro control badge
46 define('BDTUSK_IS_PC', '');
47 } else {
48 if (! defined('BDTUSK_PC')) {
49 define('BDTUSK_PC', '<span class="usk-pro-control"></span>');
50 } // pro control badge
51 define('BDTUSK_IS_PC', 'usk-disabled-control');
52 }
53
54 /**
55 * Show any alert by this function
56 *
57 * @param mixed $message [description]
58 * @param class prefix $type [description]
59 * @param boolean $close [description]
60 *
61 * @return helper [description]
62 */
63
64
65 function ultimate_store_kit_is_edit() {
66 return Plugin::$instance->editor->is_edit_mode();
67 }
68
69 function ultimate_store_kit_is_preview() {
70 return Plugin::$instance->preview->is_preview_mode();
71 }
72
73 function ultimate_store_kit_alert($message, $type = 'warning', $close = true) {
74 ?>
75 <div class="usk-alert-<?php echo esc_attr('$type'); ?>" usk-alert>
76 <?php if ($close) : ?>
77 <a class="usk-alert-close" usk-close></a>
78 <?php endif; ?>
79 <?php echo wp_kses_post($message); ?>
80 </div>
81 <?php
82 }
83
84 function ultimate_store_kit_get_alert($message, $type = 'warning', $close = true) {
85
86 $output = '<div class="usk-alert-' . $type . '" usk-alert>';
87 if ($close) :
88 $output .= '<a class="usk-alert-close" usk-close></a>';
89 endif;
90 $output .= wp_kses_post($message);
91 $output .= '</div>';
92
93 return $output;
94 }
95
96 /**
97 * all array css classes will output as proper space
98 *
99 * @param array $classes shortcode css class as array
100 *
101 * @return proper string
102 */
103
104 function ultimate_store_kit_get_post_types($args = []) {
105
106 $post_type_args = [
107 'show_in_nav_menus' => true,
108 ];
109
110 if (! empty($args['post_type'])) {
111 $post_type_args['name'] = $args['post_type'];
112 }
113
114 $_post_types = get_post_types($post_type_args, 'objects');
115
116 $post_types = ['0' => esc_html__('Select Type', 'ultimate-store-kit')];
117
118 foreach ($_post_types as $post_type => $object) {
119 $post_types[$post_type] = $object->label;
120 }
121
122 return $post_types;
123 }
124
125 /**
126 * Add REST API support to an already registered post type.
127 */
128
129 // function bdt_custom_post_type_rest_support() {
130
131 // global $wp_post_types;
132
133 // $post_types = ultimate_store_kit_get_post_types();
134
135 // foreach( $post_types as $post_type ) {
136
137 // $post_type_name = $post_type;
138
139 // if( isset( $wp_post_types[ $post_type_name ] ) ) {
140
141 // $wp_post_types[$post_type_name]->show_in_rest = true;
142
143 // $wp_post_types[$post_type_name]->rest_base = $post_type_name;
144
145 // $wp_post_types[$post_type_name]->rest_controller_class = 'WP_REST_Posts_Controller';
146
147 // }
148
149 // }
150
151 // }
152
153 // add_action( 'init', 'bdt_custom_post_type_rest_support', 25 );
154
155 function ultimate_store_kit_allow_tags($tag = null) {
156 $tag_allowed = wp_kses_allowed_html('post');
157
158 $tag_allowed['input'] = [
159 'class' => [],
160 'id' => [],
161 'name' => [],
162 'value' => [],
163 'checked' => [],
164 'type' => [],
165 ];
166 $tag_allowed['select'] = [
167 'class' => [],
168 'id' => [],
169 'name' => [],
170 'value' => [],
171 'multiple' => [],
172 'type' => [],
173 ];
174 $tag_allowed['option'] = [
175 'value' => [],
176 'selected' => [],
177 ];
178
179 $tag_allowed['title'] = [
180 'a' => [
181 'href' => [],
182 'title' => [],
183 'class' => [],
184 ],
185 'br' => [],
186 'em' => [],
187 'strong' => [],
188 'hr' => [],
189 ];
190
191 $tag_allowed['text'] = [
192 'a' => [
193 'href' => [],
194 'title' => [],
195 'class' => [],
196 ],
197 'br' => [],
198 'em' => [],
199 'strong' => [],
200 'hr' => [],
201 'i' => [
202 'class' => [],
203 ],
204 'span' => [
205 'class' => [],
206 ],
207 ];
208
209 $tag_allowed['svg'] = [
210 'svg' => [
211 'version' => [],
212 'xmlns' => [],
213 'viewbox' => [],
214 'xml:space' => [],
215 'xmlns:xlink' => [],
216 'x' => [],
217 'y' => [],
218 'style' => [],
219 ],
220 'g' => [],
221 'path' => [
222 'class' => [],
223 'd' => [],
224 ],
225 'ellipse' => [
226 'class' => [],
227 'cx' => [],
228 'cy' => [],
229 'rx' => [],
230 'ry' => [],
231 ],
232 'circle' => [
233 'class' => [],
234 'cx' => [],
235 'cy' => [],
236 'r' => [],
237 ],
238 'rect' => [
239 'x' => [],
240 'y' => [],
241 'transform' => [],
242 'height' => [],
243 'width' => [],
244 'class' => [],
245 ],
246 'line' => [
247 'class' => [],
248 'x1' => [],
249 'x2' => [],
250 'y1' => [],
251 'y2' => [],
252 ],
253 'style' => [],
254
255 ];
256
257 if ($tag == null) {
258 return $tag_allowed;
259 } elseif (is_array($tag)) {
260 $new_tag_allow = [];
261
262 foreach ($tag as $_tag) {
263 $new_tag_allow[$_tag] = $tag_allowed[$_tag];
264 }
265
266 return $new_tag_allow;
267 } else {
268 return isset($tag_allowed[$tag]) ? $tag_allowed[$tag] : [];
269 }
270 }
271
272 /**
273 * post pagination
274 */
275 function ultimate_store_kit_post_pagination($wp_query) {
276
277 /** Stop execution if there's only 1 page */
278
279 if ($wp_query->max_num_pages <= 1) {
280 return;
281 }
282
283 if (is_front_page()) {
284 $paged = (get_query_var('page')) ? get_query_var('page') : 1;
285 } else {
286 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
287 }
288
289 $max = intval($wp_query->max_num_pages);
290
291 /** Add current page to the array */
292
293 if ($paged >= 1) {
294 $links[] = $paged;
295 }
296
297 /** Add the pages around the current page to the array */
298
299 if ($paged >= 3) {
300 $links[] = $paged - 1;
301 $links[] = $paged - 2;
302 }
303
304 if (($paged + 2) <= $max) {
305 $links[] = $paged + 2;
306 $links[] = $paged + 1;
307 }
308
309 echo '<ul class="usk-pagination" aria-label="' . esc_attr__('Pagination', 'ultimate-store-kit') . '">' . "\n";
310
311 /** Previous Post Link */
312
313 if ($paged > 1) {
314 $prev_link = get_pagenum_link($paged - 1);
315 printf(
316 '<li class="usk-pagination-previous">
317 <a href="%s" aria-label="' . esc_attr__('Previous Page', 'ultimate-store-kit') . '">
318 <span class="usk-icon-arrow-left-5" aria-hidden="true"></span>
319 </a>
320 </li>' . "\n",
321 esc_url($prev_link)
322 );
323 }
324
325 /** Link to first page, plus ellipses if necessary */
326
327 if (! in_array(1, $links)) {
328 $class = 1 == $paged ? ' class="current"' : '';
329
330 printf('<li%s><a href="%s" target="_self">%s</a></li>' . "\n", wp_kses_post($class), esc_url(get_pagenum_link(1)), '1');
331
332 if (! in_array(2, $links)) {
333 echo '<li class="usk-pagination-dot-dot"><span>...</span></li>';
334 }
335 }
336
337 /** Link to current page, plus 2 pages in either direction if necessary */
338 sort($links);
339
340 foreach ((array) $links as $link) {
341 $class = $paged == $link ? ' class="usk-active"' : '';
342 printf(
343 '<li%s><a href="%s" target="_self">%s</a></li>' . "\n",
344 wp_kses_post($class),
345 esc_url(get_pagenum_link($link)),
346 esc_html($link)
347 );
348 }
349
350 /** Link to last page, plus ellipses if necessary */
351
352 if (! in_array($max, $links)) {
353
354 if (! in_array($max - 1, $links)) {
355 echo '<li class="usk-pagination-dot-dot"><span>...</span></li>' . "\n";
356 }
357
358 $class = $paged == $max ? ' class="usk-active"' : '';
359 printf(
360 '<li%s><a href="%s" target="_self">%s</a></li>' . "\n",
361 wp_kses_post($class),
362 esc_url(get_pagenum_link($max)),
363 esc_html($max)
364 );
365 }
366
367 /** Next Post Link */
368
369 if ($paged < $max) {
370 $next_link = get_pagenum_link($paged + 1);
371 printf(
372 '<li class="usk-pagination-next">
373 <a href="%s" aria-label="' . esc_attr__('Next Page', 'ultimate-store-kit') . '">
374 <span class="usk-icon-arrow-right-5" aria-hidden="true"></span>
375 </a>
376 </li>' . "\n",
377 esc_url($next_link)
378 );
379 }
380
381 echo '</ul>' . "\n";
382 }
383 function ultimate_store_kit_post_pagination__new($wp_query) {
384 $page = max(1, get_query_var('paged'), get_query_var('page'));
385 $page = absint(empty($_GET['product-page']) ? $page : $_GET['product-page']);
386 $paged = absint($page);
387
388 /** Stop execution if there's only 1 page */
389 if ($wp_query->max_num_pages <= 1) {
390 return;
391 }
392
393 $max = intval($wp_query->max_num_pages);
394
395 /** Add current page to the array */
396 if ($paged >= 1) {
397 $links[] = $paged;
398 }
399
400 /** Add the pages around the current page to the array */
401 if ($paged >= 3) {
402 $links[] = $paged - 1;
403 $links[] = $paged - 2;
404 }
405
406 if (($paged + 2) <= $max) {
407 $links[] = $paged + 2;
408 $links[] = $paged + 1;
409 }
410
411 // Get the current URL without any pagination parameters
412 $current_url = remove_query_arg(['paged', 'page', 'product-page']);
413
414 // If we're on a custom post type archive or taxonomy page, preserve the base URL
415 if (is_post_type_archive() || is_tax()) {
416 $current_url = get_pagenum_link(1, false);
417 $current_url = remove_query_arg(['paged', 'page', 'product-page'], $current_url);
418 }
419
420 echo '<ul class="usk-pagination" aria-label="' . esc_attr__('Pagination', 'ultimate-store-kit') . '">' . "\n";
421
422 /** Previous Post Link */
423 if ($paged > 1) {
424 $prev_page = $paged - 1;
425 if ($prev_page < 1) {
426 return;
427 }
428 $class = $paged == $prev_page ? ' class="current"' : '';
429 printf(
430 '<li%s><a href="%s" target="_self" aria-label="' . esc_attr__('Previous Page', 'ultimate-store-kit') . '">%s</a></li>' . "\n",
431 wp_kses_post($class),
432 esc_url(add_query_arg('product-page', $prev_page, $current_url)),
433 '<span class="usk-icon-arrow-left-5"></span>'
434 );
435 }
436
437 /** Link to first page, plus ellipses if necessary */
438 if (! in_array(1, $links)) {
439 $class = 1 == $paged ? ' class="current"' : '';
440 printf(
441 '<li%s><a href="%s" target="_self">%s</a></li>' . "\n",
442 wp_kses_post($class),
443 esc_url(add_query_arg('product-page', '1', $current_url)),
444 '1'
445 );
446 if (! in_array(2, $links)) {
447 echo '<li class="usk-pagination-dot-dot"><span>...</span></li>';
448 }
449 }
450
451 /** Link to current page, plus 2 pages in either direction if necessary */
452 sort($links);
453 foreach ((array) $links as $link) {
454 $class = $paged == $link ? ' class="usk-active"' : '';
455 printf(
456 '<li%s><a href="%s" target="_self">%s</a></li>' . "\n",
457 wp_kses_post($class),
458 esc_url(add_query_arg('product-page', $link, $current_url)),
459 esc_html($link)
460 );
461 }
462
463 /** Link to last page, plus ellipses if necessary */
464 if (! in_array($max, $links)) {
465 if (! in_array($max - 1, $links)) {
466 echo '<li class="usk-pagination-dot-dot"><span>...</span></li>' . "\n";
467 }
468 $class = $paged == $max ? ' class="usk-active"' : '';
469 printf(
470 '<li%s><a href="%s" target="_self">%s</a></li>' . "\n",
471 wp_kses_post($class),
472 esc_url(add_query_arg('product-page', $max, $current_url)),
473 esc_html($max)
474 );
475 }
476
477 /** Next Post Link */
478 if ($paged < $max) {
479 $next_page = $paged + 1;
480 if ($next_page > $max) {
481 return;
482 }
483 printf(
484 '<li%s><a href="%s" target="_self" aria-label="' . esc_attr__('Next Page', 'ultimate-store-kit') . '">%s</a></li>' . "\n",
485 wp_kses_post($class),
486 esc_url(add_query_arg('product-page', $next_page, $current_url)),
487 '<span class="usk-icon-arrow-right-5"></span>'
488 );
489 }
490
491 echo '</ul>' . "\n";
492 }
493
494 function ultimate_store_kit_template_edit_link($template_id) {
495
496 if (Ultimate_Store_Kit_Loader::elementor()->editor->is_edit_mode()) {
497
498 $final_url = add_query_arg(['elementor' => ''], get_permalink($template_id));
499
500 $output = sprintf('<a class="usk-elementor-template-edit-link" href="%s" title="%s" target="_blank"><i class="usk-icon-edit"></i></a>', esc_url($final_url), esc_html__('Edit Template', 'ultimate-store-kit'));
501
502 return $output;
503 }
504 }
505
506 function ultimate_store_kit_iso_time($time) {
507 $current_offset = (float) get_option('gmt_offset');
508 $timezone_string = get_option('timezone_string');
509
510 // Create a UTC+- zone if no timezone string exists.
511
512 //if ( empty( $timezone_string ) ) {
513 if (0 === $current_offset) {
514 $timezone_string = '+00:00';
515 } elseif ($current_offset < 0) {
516 $timezone_string = $current_offset . ':00';
517 } else {
518 $timezone_string = '+0' . $current_offset . ':00';
519 }
520
521 //}
522
523 $sub_time = [];
524 $sub_time = explode(" ", $time);
525 $final_time = $sub_time[0] . 'T' . $sub_time[1] . ':00' . $timezone_string;
526
527 return $final_time;
528 }
529
530 /**
531 * @param $currency
532 * @param int $precision
533 *
534 * @return false|string
535 */
536 function ultimate_store_kit_currency_format($currency, $precision = 1) {
537
538 if ($currency > 0) {
539
540 if ($currency < 900) {
541 // 0 - 900
542 $currency_format = number_format($currency, $precision);
543 $suffix = '';
544 } else
545
546 if ($currency < 900000) {
547 // 0.9k-850k
548 $currency_format = number_format($currency / 1000, $precision);
549 $suffix = 'K';
550 } else
551
552 if ($currency < 900000000) {
553 // 0.9m-850m
554 $currency_format = number_format($currency / 1000000, $precision);
555 $suffix = 'M';
556 } else
557
558 if ($currency < 900000000000) {
559 // 0.9b-850b
560 $currency_format = number_format($currency / 1000000000, $precision);
561 $suffix = 'B';
562 } else {
563 // 0.9t+
564 $currency_format = number_format($currency / 1000000000000, $precision);
565 $suffix = 'T';
566 }
567
568 // Remove unecessary zeroes after decimal. "1.0" -> "1"; "1.00" -> "1"
569
570 // Intentionally does not affect partials, eg "1.50" -> "1.50"
571 if ($precision > 0) {
572 $dotzero = '.' . str_repeat('0', $precision);
573 $currency_format = str_replace($dotzero, '', $currency_format);
574 }
575
576 return $currency_format . $suffix;
577 }
578
579 return false;
580 }
581
582 /**
583 * @return array
584 */
585 function ultimate_store_kit_get_menu() {
586
587 $menus = wp_get_nav_menus();
588 $items = [0 => esc_html__('Select Menu', 'ultimate-store-kit')];
589 foreach ($menus as $menu) {
590 $items[$menu->slug] = $menu->name;
591 }
592
593 return $items;
594 }
595
596 /**
597 * default get_option() default value check
598 *
599 * @param string $option settings field name
600 * @param string $section the section name this field belongs to
601 * @param string $default default text if it's not found
602 *
603 * @return mixed
604 */
605 function ultimate_store_kit_option($option, $section, $default = '') {
606
607 $options = get_option($section);
608
609 if (isset($options[$option])) {
610 return $options[$option];
611 }
612
613 return $default;
614 }
615
616 /**
617 * @return array of elementor template
618 */
619 function ultimate_store_kit_et_options() {
620
621 $templates = Ultimate_Store_Kit_Loader::elementor()->templates_manager->get_source('local')->get_items();
622 $types = [];
623
624 if (empty($templates)) {
625 $template_options = ['0' => __('Template Not Found!', 'ultimate-store-kit')];
626 } else {
627 $template_options = ['0' => __('Select Template', 'ultimate-store-kit')];
628
629 foreach ($templates as $template) {
630 $template_options[$template['template_id']] = $template['title'] . ' (' . $template['type'] . ')';
631 $types[$template['template_id']] = $template['type'];
632 }
633 }
634
635 return $template_options;
636 }
637
638 /**
639 * @return array of wp default sidebars
640 */
641 function ultimate_store_kit_sidebar_options() {
642
643 global $wp_registered_sidebars;
644 $sidebar_options = [];
645
646 if (! $wp_registered_sidebars) {
647 $sidebar_options[0] = esc_html__('No sidebars were found', 'ultimate-store-kit');
648 } else {
649 $sidebar_options[0] = esc_html__('Select Sidebar', 'ultimate-store-kit');
650
651 foreach ($wp_registered_sidebars as $sidebar_id => $sidebar) {
652 $sidebar_options[$sidebar_id] = $sidebar['name'];
653 }
654 }
655
656 return $sidebar_options;
657 }
658
659 /**
660 * @param string category name
661 *
662 * @return array of category
663 */
664 function ultimate_store_kit_get_category($taxonomy = 'product_cat') {
665
666 $post_options = [];
667
668 $post_categories = get_terms([
669 'taxonomy' => $taxonomy,
670 'hide_empty' => false,
671 ]);
672
673 if (is_wp_error($post_categories)) {
674 return $post_options;
675 }
676
677 if (false !== $post_categories and is_array($post_categories)) {
678 foreach ($post_categories as $category) {
679 // Ensure $category is an object, not an array
680 if (is_object($category) && isset($category->term_id, $category->name)) {
681 $post_options[$category->term_id] = $category->name;
682 }
683 }
684 }
685
686 return $post_options;
687 }
688
689 /**
690 * @param string parent category name
691 * @return array of parent category
692 */
693 function ultimate_store_kit_get_only_parent_cats($taxonomy = 'category') {
694
695 $parent_categories = ['none' => __('None', 'ultimate-store-kit')];
696 $args = ['parent' => 0];
697 $parent_cats = get_terms($taxonomy, $args);
698
699 foreach ($parent_cats as $parent_cat) {
700 // Ensure $parent_cat is an object, not an array
701 if (is_object($parent_cat) && isset($parent_cat->term_id, $parent_cat->name)) {
702 $parent_categories[$parent_cat->term_id] = ucfirst($parent_cat->name);
703 }
704 }
705
706 return $parent_categories;
707 }
708
709 /**
710 * @param array all ajax posted array there
711 *
712 * @return array return all setting as array
713 */
714 function ultimate_store_kit_ajax_settings($settings) {
715
716 $required_settings = [
717 'show_date' => true,
718 'show_comment' => true,
719 'show_link' => true,
720 'show_meta' => true,
721 'show_title' => true,
722 'show_excerpt' => true,
723 'show_lightbox' => true,
724 'show_thumbnail' => true,
725 'show_category' => false,
726 'show_tags' => false,
727 ];
728
729 foreach ($settings as $key => $value) {
730 if (in_array($key, $required_settings)) {
731 $required_settings[$key] = $value;
732 }
733 }
734
735 return $required_settings;
736 }
737
738 /**
739 * @return array of all transition names
740 */
741 function ultimate_store_kit_transition_options() {
742
743 $transition_options = [
744 '' => esc_html__('None', 'ultimate-store-kit'),
745 'fade' => esc_html__('Fade', 'ultimate-store-kit'),
746 'scale-up' => esc_html__('Scale Up', 'ultimate-store-kit'),
747 'scale-down' => esc_html__('Scale Down', 'ultimate-store-kit'),
748 'slide-top' => esc_html__('Slide Top', 'ultimate-store-kit'),
749 'slide-bottom' => esc_html__('Slide Bottom', 'ultimate-store-kit'),
750 'slide-left' => esc_html__('Slide Left', 'ultimate-store-kit'),
751 'slide-right' => esc_html__('Slide Right', 'ultimate-store-kit'),
752 'slide-top-small' => esc_html__('Slide Top Small', 'ultimate-store-kit'),
753 'slide-bottom-small' => esc_html__('Slide Bottom Small', 'ultimate-store-kit'),
754 'slide-left-small' => esc_html__('Slide Left Small', 'ultimate-store-kit'),
755 'slide-right-small' => esc_html__('Slide Right Small', 'ultimate-store-kit'),
756 'slide-top-medium' => esc_html__('Slide Top Medium', 'ultimate-store-kit'),
757 'slide-bottom-medium' => esc_html__('Slide Bottom Medium', 'ultimate-store-kit'),
758 'slide-left-medium' => esc_html__('Slide Left Medium', 'ultimate-store-kit'),
759 'slide-right-medium' => esc_html__('Slide Right Medium', 'ultimate-store-kit'),
760 ];
761
762 return $transition_options;
763 }
764
765 // BDT Blend Type
766 function ultimate_store_kit_blend_options() {
767 $blend_options = [
768 'multiply' => esc_html__('Multiply', 'ultimate-store-kit'),
769 'screen' => esc_html__('Screen', 'ultimate-store-kit'),
770 'overlay' => esc_html__('Overlay', 'ultimate-store-kit'),
771 'darken' => esc_html__('Darken', 'ultimate-store-kit'),
772 'lighten' => esc_html__('Lighten', 'ultimate-store-kit'),
773 'color-dodge' => esc_html__('Color-Dodge', 'ultimate-store-kit'),
774 'color-burn' => esc_html__('Color-Burn', 'ultimate-store-kit'),
775 'hard-light' => esc_html__('Hard-Light', 'ultimate-store-kit'),
776 'soft-light' => esc_html__('Soft-Light', 'ultimate-store-kit'),
777 'difference' => esc_html__('Difference', 'ultimate-store-kit'),
778 'exclusion' => esc_html__('Exclusion', 'ultimate-store-kit'),
779 'hue' => esc_html__('Hue', 'ultimate-store-kit'),
780 'saturation' => esc_html__('Saturation', 'ultimate-store-kit'),
781 'color' => esc_html__('Color', 'ultimate-store-kit'),
782 'luminosity' => esc_html__('Luminosity', 'ultimate-store-kit'),
783 ];
784
785 return $blend_options;
786 }
787
788 // BDT Position
789 function ultimate_store_kit_position() {
790 $position_options = [
791 '' => esc_html__('Default', 'ultimate-store-kit'),
792 'top-left' => esc_html__('Top Left', 'ultimate-store-kit'),
793 'top-center' => esc_html__('Top Center', 'ultimate-store-kit'),
794 'top-right' => esc_html__('Top Right', 'ultimate-store-kit'),
795 'center' => esc_html__('Center', 'ultimate-store-kit'),
796 'center-left' => esc_html__('Center Left', 'ultimate-store-kit'),
797 'center-right' => esc_html__('Center Right', 'ultimate-store-kit'),
798 'bottom-left' => esc_html__('Bottom Left', 'ultimate-store-kit'),
799 'bottom-center' => esc_html__('Bottom Center', 'ultimate-store-kit'),
800 'bottom-right' => esc_html__('Bottom Right', 'ultimate-store-kit'),
801 ];
802
803 return $position_options;
804 }
805
806 // BDT Thumbnavs Position
807 function ultimate_store_kit_thumbnavs_position() {
808 $position_options = [
809 'top-left' => esc_html__('Top Left', 'ultimate-store-kit'),
810 'top-center' => esc_html__('Top Center', 'ultimate-store-kit'),
811 'top-right' => esc_html__('Top Right', 'ultimate-store-kit'),
812 'center-left' => esc_html__('Center Left', 'ultimate-store-kit'),
813 'center-right' => esc_html__('Center Right', 'ultimate-store-kit'),
814 'bottom-left' => esc_html__('Bottom Left', 'ultimate-store-kit'),
815 'bottom-center' => esc_html__('Bottom Center', 'ultimate-store-kit'),
816 'bottom-right' => esc_html__('Bottom Right', 'ultimate-store-kit'),
817 ];
818
819 return $position_options;
820 }
821
822 function ultimate_store_kit_navigation_position() {
823 $position_options = [
824 'top-left' => esc_html__('Top Left', 'ultimate-store-kit'),
825 'top-center' => esc_html__('Top Center', 'ultimate-store-kit'),
826 'top-right' => esc_html__('Top Right', 'ultimate-store-kit'),
827 'center' => esc_html__('Center', 'ultimate-store-kit'),
828 'bottom-left' => esc_html__('Bottom Left', 'ultimate-store-kit'),
829 'bottom-center' => esc_html__('Bottom Center', 'ultimate-store-kit'),
830 'bottom-right' => esc_html__('Bottom Right', 'ultimate-store-kit'),
831 ];
832
833 return $position_options;
834 }
835
836 function ultimate_store_kit_pagination_position() {
837 $position_options = [
838 'top-left' => esc_html__('Top Left', 'ultimate-store-kit'),
839 'top-center' => esc_html__('Top Center', 'ultimate-store-kit'),
840 'top-right' => esc_html__('Top Right', 'ultimate-store-kit'),
841 'bottom-left' => esc_html__('Bottom Left', 'ultimate-store-kit'),
842 'bottom-center' => esc_html__('Bottom Center', 'ultimate-store-kit'),
843 'bottom-right' => esc_html__('Bottom Right', 'ultimate-store-kit'),
844 ];
845
846 return $position_options;
847 }
848
849 // BDT Drop Position
850 function ultimate_store_kit_drop_position() {
851 $drop_position_options = [
852 'bottom-left' => esc_html__('Bottom Left', 'ultimate-store-kit'),
853 'bottom-center' => esc_html__('Bottom Center', 'ultimate-store-kit'),
854 'bottom-right' => esc_html__('Bottom Right', 'ultimate-store-kit'),
855 'bottom-justify' => esc_html__('Bottom Justify', 'ultimate-store-kit'),
856 'top-left' => esc_html__('Top Left', 'ultimate-store-kit'),
857 'top-center' => esc_html__('Top Center', 'ultimate-store-kit'),
858 'top-right' => esc_html__('Top Right', 'ultimate-store-kit'),
859 'top-justify' => esc_html__('Top Justify', 'ultimate-store-kit'),
860 'left-top' => esc_html__('Left Top', 'ultimate-store-kit'),
861 'left-center' => esc_html__('Left Center', 'ultimate-store-kit'),
862 'left-bottom' => esc_html__('Left Bottom', 'ultimate-store-kit'),
863 'right-top' => esc_html__('Right Top', 'ultimate-store-kit'),
864 'right-center' => esc_html__('Right Center', 'ultimate-store-kit'),
865 'right-bottom' => esc_html__('Right Bottom', 'ultimate-store-kit'),
866 ];
867
868 return $drop_position_options;
869 }
870
871 // Button Size
872 function ultimate_store_kit_button_sizes() {
873 $button_sizes = [
874 'xs' => esc_html__('Extra Small', 'ultimate-store-kit'),
875 'sm' => esc_html__('Small', 'ultimate-store-kit'),
876 'md' => esc_html__('Medium', 'ultimate-store-kit'),
877 'lg' => esc_html__('Large', 'ultimate-store-kit'),
878 'xl' => esc_html__('Extra Large', 'ultimate-store-kit'),
879 ];
880
881 return $button_sizes;
882 }
883
884 // Button Size
885 function ultimate_store_kit_heading_size() {
886 $heading_sizes = [
887 'h1' => 'H1',
888 'h2' => 'H2',
889 'h3' => 'H3',
890 'h4' => 'H4',
891 'h5' => 'H5',
892 'h6' => 'H6',
893 ];
894
895 return $heading_sizes;
896 }
897
898 // Title Tags
899 function ultimate_store_kit_title_tags() {
900 $title_tags = [
901 'h1' => 'H1',
902 'h2' => 'H2',
903 'h3' => 'H3',
904 'h4' => 'H4',
905 'h5' => 'H5',
906 'h6' => 'H6',
907 'div' => 'div',
908 'span' => 'span',
909 'p' => 'p',
910 ];
911
912 return $title_tags;
913 }
914
915 function ultimate_store_kit_mask_shapes() {
916 $path = BDTUSK_ASSETS_URL . 'images/mask/';
917 $shape_name = 'shape';
918 $extension = '.svg';
919 $list = [0 => esc_html__('Select Mask', 'ultimate-store-kit')];
920
921 for ($i = 1; $i <= 20; $i++) {
922 $list[$path . $shape_name . '-' . $i . $extension] = ucwords($shape_name . ' ' . $i);
923 }
924
925 return $list;
926 }
927
928 /**
929 * This is a svg file converter function which return a svg content
930 *
931 * @param svg file
932 *
933 * @return svg content
934 */
935 function ultimate_store_kit_svg_icon($icon) {
936
937 $icon_path = BDTUSK_ASSETS_PATH . "images/svg/{$icon}.svg";
938
939 if (! file_exists($icon_path)) {
940 return false;
941 }
942
943 ob_start();
944
945 include $icon_path;
946
947 $svg = ob_get_clean();
948
949 return $svg;
950 }
951
952 /**
953 * @param array CSV file data
954 * @param string $delimiter
955 * @param false $header
956 *
957 * @return string
958 */
959 function ultimate_store_kit_parse_csv($csv, $delimiter = ';', $header = true) {
960
961 if (! is_string($csv)) {
962 return '';
963 }
964
965 if (! function_exists('str_getcsv')) {
966 return $csv;
967 }
968
969 $html = '';
970 $rows = explode(PHP_EOL, $csv);
971 $headRow = 1;
972
973 foreach ($rows as $row) {
974
975 if ($headRow == 1 and $header) {
976 $html .= '<thead><tr>';
977 } else {
978 $html .= '<tr>';
979 }
980
981 foreach (str_getcsv($row, $delimiter) as $cell) {
982
983 $cell = trim($cell);
984
985 $html .= $header
986 ? '<th>' . $cell . '</th>'
987 : '<td>' . $cell . '</td>';
988 }
989
990 if ($headRow == 1 and $header) {
991 $html .= '</tr></thead><tbody>';
992 } else {
993 $html .= '</tr>';
994 }
995
996 $headRow++;
997 $header = false;
998 }
999
1000 return '<table>' . $html . '</tbody></table>';
1001 }
1002
1003 function ultimate_store_kit_dashboard_link($suffix = '') {
1004 return add_query_arg(['page' => 'ultimate-store-kit' . $suffix], admin_url('admin.php'));
1005 }
1006
1007 /**
1008 * @param int $limit default limit is 25 word
1009 * @param bool $strip_shortcode if you want to strip shortcode from excert text
1010 * @param string $trail trail string default is ...
1011 *
1012 * @return string return custom limited excerpt text
1013 */
1014 function ultimate_store_kit_custom_excerpt($limit = 25, $strip_shortcode = false, $trail = '') {
1015
1016 $output = get_the_content();
1017
1018 if ($limit) {
1019 $output = wp_trim_words($output, $limit, $trail);
1020 }
1021
1022 if ($strip_shortcode) {
1023 $output = strip_shortcodes($output);
1024 }
1025
1026 return wpautop($output);
1027 }
1028
1029 function usk_get_order_options() {
1030 $options = [
1031 'title' => __('Title', 'ultimate-store-kit'),
1032 'ID' => __('ID', 'ultimate-store-kit'),
1033 'date' => __('Date', 'ultimate-store-kit'),
1034 'rand' => __('Random', 'ultimate-store-kit'),
1035 '_price' => __('Product Price', 'ultimate-store-kit'),
1036 'total_sales' => __('Top Seller', 'ultimate-store-kit'),
1037 'comment_count' => __('Most Reviewed', 'ultimate-store-kit'),
1038 '_wc_average_rating' => __('Top Rated', 'ultimate-store-kit'),
1039 ];
1040
1041 return apply_filters('usk_order_options', $options);
1042 }
1043
1044 //wishlist
1045 function ultimate_store_kit_get_wishlist($user_id = 0) {
1046 $_wishlist_key = '_ultimate_store_kit_wishlist';
1047 $_wishlist = [];
1048
1049 if (isset($_COOKIE[$_wishlist_key])) {
1050 $cookie_data = stripslashes($_COOKIE[$_wishlist_key]);
1051 $decoded_data = json_decode($cookie_data, true);
1052
1053 if (json_last_error() === JSON_ERROR_NONE && is_array($decoded_data)) {
1054 $_wishlist = $decoded_data;
1055 }
1056 }
1057
1058 return apply_filters('ultimate_store_kit_wishlist', array_unique($_wishlist));
1059 }
1060
1061 function usk_get_taxonomies() {
1062 $taxonomy_list = get_object_taxonomies('product');
1063 $taxonomies = [
1064 'search' => 'Search',
1065 'price' => 'Price',
1066 'orderby' => 'Orderby',
1067 'order' => 'Order',
1068 ];
1069
1070 foreach ($taxonomy_list as $_taxonomy) {
1071 $taxonomy = get_taxonomy($_taxonomy);
1072
1073 if ($taxonomy->show_ui) {
1074 $taxonomies[$_taxonomy] = $taxonomy->label;
1075 }
1076 }
1077
1078 return $taxonomies;
1079 }
1080
1081 function ultimate_store_kit_hide_on_class($selectors) {
1082 $element_hide_on = '';
1083
1084 if (! empty($selectors)) {
1085
1086 foreach ($selectors as $element) {
1087
1088 if ($element == 'desktop') {
1089 $element_hide_on .= ' usk-hide-desktop';
1090 }
1091
1092 if ($element == 'tablet') {
1093 $element_hide_on .= ' usk-hide-tablet';
1094 }
1095
1096 if ($element == 'mobile') {
1097 $element_hide_on .= ' usk-hide-mobile';
1098 }
1099 }
1100 }
1101
1102 return $element_hide_on;
1103 }
1104
1105 function ultimate_store_kit_wc_product_quick_view_content($product_id) {
1106 wp_verify_nonce('ajax-usk-quick-view-nonce', 'usk-quick-view-modal-sc');
1107 global $woocommerce;
1108 global $post;
1109
1110 if (intval($product_id)) {
1111 $post = get_post($product_id);
1112 $next_post = get_next_post();
1113 $prev_post = get_previous_post();
1114
1115 wp('p=' . $product_id . '&post_type=product');
1116 ob_start();
1117 ?>
1118 <div class="usk-modal-page">
1119 <?php
1120 while (have_posts()) :
1121 the_post(); ?>
1122 <div class="usk-modal-product">
1123 <div id="product-<?php the_ID(); ?>" <?php post_class('product'); ?>>
1124 <div class="usk-modal-image-wrapper">
1125 <?php do_action('ultimate_store_kit_quick_florence_grid_view_product_images'); ?>
1126 <div class="usk-onsale">
1127 <?php do_action('ultimate_store_kit_wc_product_quick_view_product_sale_flash'); ?>
1128 </div>
1129 </div>
1130 <div class="usk-modal-content-box">
1131 <a href="<?php echo esc_url(get_permalink()); ?>" class="usk-product-title">
1132 <?php do_action('ultimate_store_kit_quick_view_product_title'); ?>
1133 </a>
1134 <div class="usk-rating">
1135 <?php do_action('ultimate_store_kit_quick_view_product_single_rating'); ?>
1136 </div>
1137 <div class="usk-product-price">
1138 <?php do_action('ultimate_store_kit_quick_view_product_single_price'); ?>
1139 </div>
1140 <div class="usk-product-meta">
1141 <div class="usk-sku-wrapper">
1142 <?php do_action('ultimate_store_kit_quick_view_product_single_meta'); ?>
1143 </div>
1144 </div>
1145 <div class="usk-product-desc">
1146 <?php do_action('ultimate_store_kit_quick_view_product_single_excerpt'); ?>
1147 </div>
1148
1149 <div class="usk-quick-action-wrap">
1150 <?php do_action('ultimate_store_kit_quick_view_product_single_add_to_cart'); ?>
1151 </div>
1152 </div>
1153 </div>
1154 </div>
1155 <?php endwhile; ?>
1156 </div>
1157
1158 <?php
1159 $content = ob_get_clean();
1160 echo wp_kses_post($content);
1161 ?>
1162 <script type="text/javascript">
1163 jQuery(document).ready(function($) {
1164 // Load required WooCommerce scripts
1165 var scripts = [
1166 '<?php echo esc_url(plugins_url('assets/js/prettyPhoto/jquery.prettyPhoto.init.js', WC_PLUGIN_FILE)); ?>',
1167 '<?php echo esc_url(plugins_url('assets/js/frontend/add-to-cart-variation.min.js', WC_PLUGIN_FILE)); ?>',
1168 '<?php echo esc_url(plugins_url('assets/js/frontend/add-to-cart.min.js', WC_PLUGIN_FILE)); ?>',
1169 '<?php echo esc_url(plugins_url('assets/js/frontend/single-product.min.js', WC_PLUGIN_FILE)); ?>'
1170 ];
1171
1172 // Load scripts sequentially
1173 function loadScript(index) {
1174 if (index >= scripts.length) {
1175 initializeWooCommerce();
1176 return;
1177 }
1178
1179 $.getScript(scripts[index], function() {
1180 loadScript(index + 1);
1181 });
1182 }
1183
1184 function initializeWooCommerce() {
1185 // Initialize WooCommerce add to cart functionality
1186 var wc_add_to_cart_variation_params = {
1187 "ajax_url": "<?php echo admin_url('admin-ajax.php'); ?>",
1188 "i18n_view_cart": "<?php echo esc_js(__('View cart', 'ultimate-store-kit')); ?>",
1189 "cart_url": "<?php echo esc_url(wc_get_cart_url()); ?>",
1190 "is_cart": "<?php echo is_cart() ? '1' : '0'; ?>",
1191 "cart_redirect_after_add": "<?php echo get_option('woocommerce_cart_redirect_after_add') ? '1' : '0'; ?>"
1192 };
1193
1194 // Initialize variation forms
1195 $(document.body).trigger('wc_variation_form');
1196
1197 // Initialize add to cart buttons
1198 $(document.body).trigger('wc_fragments_refreshed');
1199 $(document.body).trigger('wc_fragments_loaded');
1200 $(document.body).trigger('added_to_cart');
1201 }
1202
1203 // Start loading scripts
1204 // loadScript(0);
1205 });
1206 </script>
1207 <?php
1208 exit();
1209 }
1210 }
1211
1212 function ultimate_store_kit_quick_view_product_images() {
1213 global $post, $product; ?>
1214 <div class="images">
1215 <?php
1216
1217 if (has_post_thumbnail()) {
1218 $attachment_count = count($product->get_gallery_image_ids());
1219 $gallery = $attachment_count > 0 ? '[product-gallery]' : '';
1220 $props = wc_get_product_attachment_props(get_post_thumbnail_id(), $post);
1221 $image = get_the_post_thumbnail($post->ID, apply_filters('single_product_large_thumbnail_size', 'shop_single'), [
1222 'title' => $props['title'],
1223 'alt' => $props['alt'],
1224 ]);
1225 echo wp_kses_post(apply_filters('woocommerce_single_product_image_html', sprintf('<a href="%s" itemprop="image" class="usk-product woocommerce-main-image zoom" title="%s" data-rel="prettyPhoto' . $gallery . '">%s</a>', $props['url'], $props['caption'], $image), $post->ID));
1226 } else {
1227 echo wp_kses_post(apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="%s" />', wc_placeholder_img_src(), esc_html__('Placeholder', 'ultimate-store-kit')), $post->ID));
1228 }
1229
1230 $attachment_ids = $product->get_gallery_image_ids();
1231
1232 if ($attachment_ids) :
1233 $loop = 0;
1234 $columns = apply_filters('woocommerce_product_thumbnails_columns', 3);
1235 ?>
1236 <div class="thumbnails columns-<?php echo esc_attr($columns); ?>">
1237 <?php
1238
1239 foreach ($attachment_ids as $attachment_id) {
1240 $classes = ['thumbnail'];
1241
1242 if ($loop === 0 || $loop % $columns === 0) {
1243 $classes[] = 'first';
1244 }
1245
1246 if (($loop + 1) % $columns === 0) {
1247 $classes[] = 'last';
1248 }
1249
1250 $image_link = wp_get_attachment_url($attachment_id);
1251
1252 if (! $image_link) {
1253 continue;
1254 }
1255
1256 $image_title = esc_attr(get_the_title($attachment_id));
1257 $image_caption = esc_attr(get_post_field('post_excerpt', $attachment_id));
1258 $image = wp_get_attachment_image($attachment_id, apply_filters('single_product_small_thumbnail_size', 'shop_thumbnail'), 0, $attr = [
1259 'title' => $image_title,
1260 'alt' => $image_title,
1261 ]);
1262 $image_class = esc_attr(implode(' ', $classes));
1263 echo wp_kses_post(apply_filters('woocommerce_single_product_image_thumbnail_html', sprintf('<a href="%s" class="%s" title="%s" >%s</a>', $image_link, $image_class, $image_caption, $image), $attachment_id, $post->ID, $image_class));
1264 $loop++;
1265 }
1266
1267 ?>
1268 </div>
1269 <?php endif; ?>
1270 </div>
1271 <?php
1272 }
1273
1274
1275 /**
1276 * License Validation
1277 */
1278 if (! function_exists('usk_license_validation')) {
1279 function usk_license_validation() {
1280
1281 if (function_exists('_is_usk_pro_activated') && false === _is_usk_pro_activated()) {
1282 return false;
1283 }
1284
1285 $license_key = trim(get_option('ultimate_store_kit_license_key'));
1286
1287 if (isset($license_key) && ! empty($license_key)) {
1288 return true;
1289 } else {
1290 return false;
1291 }
1292 return false;
1293 }
1294 }
1295
1296
1297
1298 function usk_get_compare_products($user_id = 0) {
1299 $_compare_products_key = '_ultimate_store_kit_compare_products';
1300 $_compare_products = [];
1301 if ($user_id != 0) {
1302 $_compare_products = get_user_meta($user_id, $_compare_products_key, true) ?: [];
1303 } elseif (isset($_COOKIE[$_compare_products_key])) {
1304 //$_compare_products = unserialize(stripslashes($_COOKIE[sanitize_text_field($_compare_products_key)]));
1305
1306 $cookie_value = sanitize_text_field($_COOKIE[$_compare_products_key]);
1307 $_compare_products = json_decode(stripslashes($cookie_value), true);
1308
1309 // Check if JSON decoding failed
1310 if (! is_array($_compare_products)) {
1311 $_compare_products = [];
1312 }
1313 }
1314
1315 return apply_filters('ultimate_store_kit_compare_products', array_unique($_compare_products));
1316 }
1317
1318 function usk_get_compare_products_count() {
1319 $count = 0;
1320 $user_id = get_current_user_id();
1321 $products = usk_get_compare_products($user_id);
1322 if (is_array($products)) {
1323 $count = count($products);
1324 }
1325 return $count;
1326 }
1327
1328 //if (!function_exists('ultimate_store_kit_get_compare_product_slug')) {
1329 // function ultimate_store_kit_compare_product_slug() {
1330 // return 'compare-products';
1331 // }
1332 //}
1333
1334 if (! function_exists('ultimate_store_kit_compare_product_page')) {
1335 function ultimate_store_kit_compare_product_page() {
1336 if ($postId = intval(get_option('bdt_usk_compare_products_page_id'))) {
1337 $post = get_post($postId);
1338 if ($post && $post->post_status == 'publish') {
1339 return $post->ID;
1340 }
1341 }
1342 }
1343 }
1344
1345 if (! function_exists('ultimate_store_kit_is_compare_product_page')) {
1346 function ultimate_store_kit_is_compare_product_page() {
1347 if ($page = ultimate_store_kit_compare_product_page()) {
1348 // return is_page( $page->ID );
1349 return is_page($page);
1350 }
1351 }
1352 }
1353
1354 /**
1355 * Helper function to check if variation swatches Pro is active
1356 *
1357 * @return bool
1358 */
1359 function usk_has_variation_swatches_support() {
1360 return class_exists('UltimateStoreKitPro\\VariationSwatches\\Swatches');
1361 }
1362
1363 /**
1364 * Helper function to load variation swatches scripts and styles
1365 */
1366 function usk_load_variation_swatches_assets() {
1367 // Always load the grid variations script for variation support
1368 wp_register_script('usk-grid-variations', BDTUSK_ASSETS_URL . 'js/modules/grid-variations.js', ['jquery'], BDTUSK_VER, true);
1369 wp_localize_script('usk-grid-variations', 'usk_vars', array(
1370 'ajax_url' => admin_url('admin-ajax.php'),
1371 'nonce' => wp_create_nonce('usk_variations')
1372 ));
1373 }
1374 add_action('wp_enqueue_scripts', 'usk_load_variation_swatches_assets', 20);
1375
1376 // Hook into AJAX variation selection to update product image
1377 function usk_ajax_variation_image_update() {
1378 if (!isset($_POST['variation_id']) || !isset($_POST['product_id'])) {
1379 wp_send_json_error('Missing required parameters');
1380 return;
1381 }
1382
1383 $variation_id = absint($_POST['variation_id']);
1384 $product_id = absint($_POST['product_id']);
1385
1386 $variation = wc_get_product($variation_id);
1387 if (!$variation) {
1388 wp_send_json_error('Invalid variation');
1389 return;
1390 }
1391
1392 $image_id = $variation->get_image_id();
1393 $image_url = '';
1394
1395 if ($image_id) {
1396 $image_url = wp_get_attachment_image_url($image_id, 'woocommerce_thumbnail');
1397 } else {
1398 // If variation has no image, use the parent product image
1399 $parent = wc_get_product($product_id);
1400 $parent_image_id = $parent->get_image_id();
1401 if ($parent_image_id) {
1402 $image_url = wp_get_attachment_image_url($parent_image_id, 'woocommerce_thumbnail');
1403 }
1404 }
1405
1406 wp_send_json_success(array('image_url' => $image_url));
1407 }
1408 add_action('wp_ajax_usk_get_variation_image', 'usk_ajax_variation_image_update');
1409 add_action('wp_ajax_nopriv_usk_get_variation_image', 'usk_ajax_variation_image_update');
1410
1411 // Start: Add to cart quantity buttons conversion
1412 if (! function_exists('usk_display_quantity_minus')) {
1413 function usk_display_quantity_minus() {
1414 if (! is_product()) return;
1415 echo '<button type="button" class="bdt-add-to-cart-qty-minus" ><i class="usk-icon-minus3"></i></button>';
1416 }
1417 }
1418
1419 if (! function_exists('usk_display_quantity_plus')) {
1420 function usk_display_quantity_plus() {
1421 if (! is_product()) return;
1422 echo '<button type="button" class="bdt-add-to-cart-qty-plus" ><i class="usk-icon-plus3"></i></button>';
1423 }
1424 }
1425
1426 if (! function_exists('usk_add_cart_quantity_plus_minus')) {
1427 function usk_add_cart_quantity_plus_minus() {
1428
1429 echo '<style>
1430 input[type="number"]::-webkit-outer-spin-button,
1431 input[type="number"]::-webkit-inner-spin-button {
1432 -webkit-appearance: none;
1433 margin: 0;
1434 }
1435
1436 input[type="number"] {
1437 -moz-appearance: textfield; /* Firefox */
1438 }
1439 </style>';
1440
1441 wc_enqueue_js("
1442 $(document).off('click.bdtQtyHandler'); // Remove previous handler
1443 $(document).on('click.bdtQtyHandler', 'button.bdt-add-to-cart-qty-plus, button.bdt-add-to-cart-qty-minus', function(e) {
1444 e.preventDefault();
1445 var qty = $(this).closest('form.cart').find('.qty');
1446 var val = parseFloat(qty.val()) || 0;
1447 var max = parseFloat(qty.attr('max')) || Infinity;
1448 var min = parseFloat(qty.attr('min')) || 0;
1449 var step = parseFloat(qty.attr( 'step' ));
1450
1451 if ($(this).is('.bdt-add-to-cart-qty-plus')) {
1452 qty.val(Math.min(val + step, max)).trigger('change');
1453 } else {
1454 qty.val(Math.max(val - step, min)).trigger('change');
1455 }
1456 });
1457 ");
1458 }
1459 }
1460
1461 if (! function_exists('usk_setup_quantity_buttons')) {
1462 function usk_setup_quantity_buttons() {
1463 if (function_exists('is_product')) {
1464 // Remove the default version
1465 remove_all_actions('woocommerce_before_quantity_input_field');
1466 remove_all_actions('woocommerce_after_quantity_input_field');
1467 remove_all_actions('woocommerce_before_single_product');
1468
1469 // Add our version
1470 add_action('woocommerce_before_quantity_input_field', 'usk_display_quantity_minus');
1471 add_action('woocommerce_after_quantity_input_field', 'usk_display_quantity_plus');
1472 add_action('woocommerce_after_single_product', 'usk_add_cart_quantity_plus_minus');
1473 }
1474 }
1475 }
1476 // End: Add to cart quantity buttons conversion
1477