PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 3.1.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v3.1.1
4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / utils / helper.php
shopengine / utils Last commit date
controls-helper.php 3 years ago elementor-data-map.php 3 years ago global-helper.php 3 years ago helper.php 3 years ago notice.php 3 years ago shipping-calculation.php 3 years ago
helper.php
549 lines
1 <?php
2
3 namespace ShopEngine\Utils;
4
5
6 use ShopEngine\Core\Builders\Action;
7 use ShopEngine\Core\Template_Cpt;
8
9 defined('ABSPATH') || exit;
10
11 /**
12 * Global helper class.
13 *
14 * @since 1.0.0
15 */
16 class Helper {
17
18 public static function is_elementor_active() {
19
20 return did_action('elementor/loaded');
21 }
22
23 public static function is_gutenberg_active() {
24
25 return !did_action('elementor/loaded');
26 }
27
28 public static function is_elementor_editor_mode() {
29
30 if(self::is_elementor_active()) {
31
32 return \Elementor\Plugin::$instance->editor->is_edit_mode();
33 }
34
35 return false;
36 }
37
38
39 public static function get_elementor_css_uri($pid) {
40
41 global $blog_id;
42
43 $wp_upload_dir = wp_upload_dir(null, false);
44
45 $base = $wp_upload_dir['baseurl'] . '/elementor/css/';
46
47 return set_url_scheme($base . 'post-' . $pid . '.css');
48 }
49
50 public static function add_to_url($url, $param) {
51 $info = parse_url( $url );
52 $query = [];
53
54 if(isset($info['query'])){
55 parse_str( $info['query'], $query );
56 }
57 return (isset($info['scheme']) ? $info['scheme'] . '://' : '') . ($info['host'] ?? '') .( $info['path'] ?? '' ). '?' . http_build_query( $query ? array_merge( $query, $param ) : $param );
58 }
59
60
61 /**
62 * Auto generate classname from path.
63 *
64 * @since 1.0.0
65 * @access public
66 */
67 public static function make_classname($dirname) {
68 $dirname = pathinfo($dirname, PATHINFO_FILENAME);
69 $class_name = explode('-', $dirname);
70 $class_name = array_map('ucfirst', $class_name);
71 $class_name = implode('_', $class_name);
72
73 return $class_name;
74 }
75
76 public static function get_kses_array()
77 {
78 return [
79 'a' => [
80 'class' => [],
81 'href' => [],
82 'rel' => [],
83 'title' => [],
84 'target' => [],
85 'data-quantity' => [],
86 'data-product_id' => [],
87 'data-product_sku' => [],
88 'data-pid' => [],
89 'aria-label' => [],
90 ],
91 'abbr' => [
92 'title' => [],
93 ],
94 'b' => [],
95 'blockquote' => [
96 'cite' => [],
97 ],
98 'cite' => [
99 'title' => [],
100 ],
101 'code' => [],
102 'del' => [
103 'datetime' => [],
104 'title' => [],
105 ],
106 'dd' => [],
107 'div' => [
108 'class' => [],
109 'title' => [],
110 'style' => [],
111 'data-product-id' => [],
112 'data-attribute_name' => []
113 ],
114 'dl' => [],
115 'dt' => [],
116 'em' => [],
117 'h1' => [
118 'class' => [],
119 ],
120 'h2' => [
121 'class' => [],
122 ],
123 'h3' => [
124 'class' => [],
125 ],
126 'h4' => [
127 'class' => [],
128 ],
129 'h5' => [
130 'class' => [],
131 ],
132 'h6' => [
133 'class' => [],
134 ],
135 'i' => [
136 'class' => [],
137 ],
138 'img' => [
139 'alt' => [],
140 'class' => [],
141 'height' => [],
142 'src' => [],
143 'width' => [],
144 'decoding' => [],
145 'loading' => [],
146 'srcset' => [],
147 'sizes' => []
148 ],
149 'li' => [
150 'class' => [],
151 ],
152 'ol' => [
153 'class' => [],
154 ],
155 'p' => [
156 'class' => [],
157 ],
158 'q' => [
159 'cite' => [],
160 'title' => [],
161 ],
162 'span' => [
163 'class' => [],
164 'title' => [],
165 'style' => [],
166 ],
167 'iframe' => [
168 'width' => [],
169 'height' => [],
170 'scrolling' => [],
171 'frameborder' => [],
172 'allow' => [],
173 'src' => [],
174 ],
175 'strike' => [],
176 'br' => [],
177 'strong' => [],
178 'data-wow-duration' => [],
179 'data-wow-delay' => [],
180 'data-wallpaper-options' => [],
181 'data-stellar-background-ratio' => [],
182 'ul' => [
183 'class' => [],
184 ],
185 'button' => [
186 'class' => [],
187 'title' => [],
188 'data-share-url' => [],
189 'data-message' => []
190 ]
191 ];
192 }
193
194 public static function kses($raw) {
195
196 if(function_exists('wp_kses')) { // WP is here
197 return wp_kses($raw, self::get_kses_array());
198 } else {
199 return $raw;
200 }
201 }
202
203 public static function kspan($text) {
204 return str_replace(['{', '}'], ['<span>', '</span>'], self::kses($text));
205 }
206
207 public static function category_list_by_taxonomy($taxonomy = '') {
208 $query_args = [
209 'orderby' => 'ID',
210 'order' => 'DESC',
211 'hide_empty' => 1,
212 'taxonomy' => $taxonomy,
213 ];
214
215 $categories = get_categories($query_args);
216
217 return $categories;
218 }
219
220 public static function trim_words($text, $num_words) {
221 return wp_trim_words($text, $num_words, '');
222 }
223
224 public static function array_push_assoc($array, $key, $value) {
225 $array[$key] = $value;
226
227 return $array;
228 }
229
230 public static function render($content) {
231 if(stripos($content, "shopengine-has-lisence") !== false) {
232 return null;
233 }
234
235 return $content;
236 }
237
238 public static function render_elementor_content($content_id) {
239 $elementor_instance = \Elementor\Plugin::instance();
240
241 return $elementor_instance->frontend->get_builder_content_for_display($content_id);
242 }
243
244 public static function esc_options($str, $options = [], $default = '') {
245 if(!in_array($str, $options)) {
246 return $default;
247 }
248
249 return $str;
250 }
251
252 public static function img_meta($id) {
253 $attachment = get_post($id);
254 if($attachment == null || $attachment->post_type != 'attachment') {
255 return null;
256 }
257
258 return [
259 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
260 'caption' => $attachment->post_excerpt,
261 'description' => $attachment->post_content,
262 'href' => get_permalink($attachment->ID),
263 'src' => $attachment->guid,
264 'title' => $attachment->post_title,
265 ];
266 }
267
268 public static function _product_tag_sale_badge($settings = null) {
269 global $product;
270 $terms = get_the_terms(get_the_ID(), 'product_tag');
271
272 $badge_position = (isset($settings['badge_position']) && !empty($settings['badge_position'])) ? esc_attr($settings['badge_position']) : 'top-right';
273 $badge_align = (isset($settings['badge_align']) && !empty($settings['badge_align'])) ? esc_attr($settings['badge_align']) : 'horizontal';
274
275 if($product->is_on_sale() || !empty($terms)) : ?>
276 <div class="product-tag-sale-badge position-<?php echo esc_attr($badge_position); ?> align-<?php echo esc_attr($badge_align); ?>">
277 <ul>
278 <?php if(!empty($terms)) : $term = $terms[0];
279 $bg = get_term_meta($term->term_id, 'shopengine_tag_bg_color', true);
280 ?>
281 <?php if(!empty(self::_discount_percentage())) : ?>
282 <li class="badge no-link off"><?php echo '-' . esc_html(self::_discount_percentage()) . '%'; ?></li>
283 <?php endif; ?>
284 <li class="badge tag">
285 <a title="<?php echo esc_html($term->name,'shopengine');?>" <?php if(!empty($bg)) : ?>style="background-color:<?php echo esc_attr($bg); ?>" <?php endif; ?>
286 href="<?php echo esc_url(get_term_link($term->term_id)); ?>"><?php echo esc_html($term->name); ?></a>
287 </li>
288 <?php endif;
289
290 if($product->is_on_sale()) {
291 echo "<li class='badge no-link sale'>" . esc_html__('Sale!', 'shopengine') . "</li>";
292 }
293 ?>
294 </ul>
295 </div>
296 <?php
297 endif;
298 }
299
300 public static function _product_image($settings = null) {
301 global $product;
302 ?>
303 <div class='product-thumb'>
304 <a title="<?php esc_html_e('Product Thumbnail','shopengine')?>" href="<?php echo esc_url(get_the_permalink()); ?>">
305 <?php shopengine_content_render(woocommerce_get_product_thumbnail($product->get_id())) ?>
306 </a>
307
308 <!-- end sale date -->
309 <?php
310 if(!empty($settings['counter_position']) && $settings['counter_position'] == 'image') {
311 self::_product_sale_end_date($settings);
312 }
313 ?>
314 <!-- tag and sale badge -->
315 <?php self::_product_tag_sale_badge($settings); ?>
316
317 <!-- show group buttons -->
318 <?php
319 if(isset($settings['shopengine_group_btns']) && $settings['shopengine_group_btns'] === 'yes') {
320
321 $data_attr = apply_filters('shopengine/group_btns/optional_tooltip_data_attr', '');
322
323 ?>
324 <div class="loop-product--btns" <?php echo esc_attr($data_attr)?>>
325 <div class="loop-product--btns-inner">
326 <?php woocommerce_template_loop_add_to_cart(); ?>
327 </div>
328 </div>
329 <?php
330 }
331 ?>
332
333 </div>
334 <?php
335 }
336
337 public static function _product_sale_end_date($settings) {
338 $date = get_post_meta(get_the_id(), '_sale_price_dates_to', true);
339 if(!empty($date)) :
340 $formatted_date = date("Y-m-d", $date);
341 $config = [
342 'days' => esc_html__('Days', 'shopengine'),
343 'hours' => esc_html__('Hours', 'shopengine'),
344 'minutes' => esc_html__('Minutes', 'shopengine'),
345 'seconds' => esc_html__('Seconds', 'shopengine'),
346 ];
347
348 ?>
349 <div data-prefix="<?php echo !empty($settings['counter_prefix']) ? esc_attr($settings['counter_prefix']) : ''; ?>"
350 class="product-end-sale-timer <?php echo !empty($settings['counter_position']) ? 'counter-position-' . esc_attr($settings['counter_position']) : ''; ?>"
351 data-config='<?php echo json_encode($config); ?>'
352 data-date="<?php echo esc_attr($formatted_date); ?>"></div>
353 <?php
354 endif;
355 }
356
357 public static function _product_category($settings = null) {
358 global $product;
359
360 $terms = get_the_terms($product->get_id(), 'product_cat');
361 $terms_count = count($terms);
362 $category = esc_html__('Product Category','shopengine');
363
364 if($terms_count > 0) {
365 echo "<div class='product-category'><ul>";
366 foreach($terms as $key => $term) {
367 $sperator = $key !== ($terms_count - 1) ? ',' : '';
368 echo "<li><a title='" . esc_attr($category) . "' href='" . esc_url(get_term_link($term->term_id)) . "'>" . esc_html($term->name) . esc_url($sperator) . "</a></li>";
369 }
370 echo "</ul></div>";
371 }
372 }
373
374 public static function _discount_percentage($settings = null) {
375 global $product;
376
377 $product_data = $product->get_data();
378 $show_tag = (isset($settings['show_tag']) && !empty($settings['show_tag'])) ? esc_attr($settings['show_tag']) : 'yes';
379 $output = '';
380 if($show_tag == 'yes' && !empty($product_data['regular_price']) && $product_data['sale_price']) {
381 $percentage = round((($product_data['regular_price'] - $product_data['sale_price']) / $product_data['regular_price']) * 100);
382
383 return $percentage;
384 }
385
386 return '';
387 }
388
389
390 public static function _product_title($settings = null) {
391 global $product;
392 ?>
393 <h3 class='product-title'>
394 <a title="<?php esc_html_e('View Product Details','shopengine')?>" href="<?php echo esc_url(get_the_permalink($product->get_id())); ?>"><?php echo esc_html(get_the_title($product->get_id())); ?></a>
395 </h3>
396 <?php
397 }
398
399 public static function _product_rating($settings = null) {
400
401 global $product;
402 ?>
403 <div class="product-rating">
404 <?php
405 if($product->get_rating_count() > 0) {
406 woocommerce_template_loop_rating();
407 } else {
408 shopengine_content_render(sprintf('<div class="star-rating">%1$s</div>', wc_get_star_rating_html(0, 0)));
409 }
410
411 // review count
412 shopengine_content_render(sprintf('<span class="rating-count">(%1$s)</span>', $product->get_review_count()));
413 ?>
414 </div>
415 <?php
416 }
417
418
419 public static function _product_price($settings = null) {
420 ?>
421 <div class="product-price">
422 <?php woocommerce_template_single_price(); ?>
423 </div>
424 <?php
425 }
426
427 public static function _product_description($settings = null) {
428 global $product;
429 $product_data = $product->get_data($product->get_id());
430 ?>
431 <div class="prodcut-description">
432 <?php shopengine_content_render(apply_filters('shopengine_product_short_description', $product_data['description']))?>
433 </div>
434
435 <?php
436 }
437
438 public static function _product_buttons($settings = null) {
439
440 if( isset($settings['shopengine_group_btns']) && $settings['shopengine_group_btns'] === 'yes'): ?>
441 <div class="add-to-cart-bt">
442 <?php woocommerce_template_loop_add_to_cart(); ?>
443 </div>
444 <?php endif;
445 }
446
447
448 /**
449 * todo - check the keys for refund and cancelled [wc-cancelled, wc-refunded ]
450 *
451 * @param $product_id
452 * @param int $variation_id
453 * @return int
454 */
455 public static function get_total_sale_count($product_id, $variation_id = 0) {
456
457 global $wpdb;
458
459 $result = $wpdb->get_row( $wpdb->prepare( "SELECT sum(lookup.product_qty) as total FROM `'.$wpdb->prefix.'wc_order_product_lookup` as lookup
460 LEFT JOIN '.$wpdb->prefix.'wc_order_stats AS stat on lookup.order_id = stat.order_id
461 WHERE `product_id` = %d and variation_id = %d
462 and stat.status NOT IN (\'wc-cancelled\', \'wc-refunded\')", intval( $product_id ), intval( $variation_id ) ) );
463 $total = is_object( $result ) ? $result->total : 0;
464
465 return intval( $total );
466 }
467
468
469 public static function is_guest_checkout_allowed() {
470
471 return 'yes' === get_option('woocommerce_enable_guest_checkout');
472 }
473
474 public static function is_login_allowed_during_checkout() {
475
476 return 'yes' === get_option('woocommerce_enable_checkout_login_reminder');
477 }
478
479
480 private static function generate_products_meta() {
481 global $wpdb;
482 $post_type = 'product';
483 $meta_keys = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT($wpdb->postmeta.meta_key)
484 FROM $wpdb->posts
485 LEFT JOIN $wpdb->postmeta
486 ON $wpdb->posts.ID = $wpdb->postmeta.post_id
487 WHERE $wpdb->posts.post_type = %s
488 AND $wpdb->postmeta.meta_key != ''
489 AND $wpdb->postmeta.meta_key NOT RegExp '(^[_0-9].+$)'
490 AND $wpdb->postmeta.meta_key NOT RegExp '(^[0-9]+$)'", $post_type ) );
491 //set_transient( 'shopengine-all-products_meta_keys', $meta_keys, 60 * 60 * 0.01 );
492
493 return $meta_keys;
494 }
495
496 public static function get_products_meta_keys() {
497 //$cache = get_transient( 'shopengine-all-products_meta_keys' );
498 return static::generate_products_meta();
499 }
500
501
502
503 public static function get_template_type($pid) {
504
505 return get_post_meta($pid, Action::get_meta_key_for_type(), true);
506 }
507
508 public static function get_template_builder_type($pid) {
509
510 return get_post_meta($pid, Action::get_meta_key_for_edit_with(), true);
511 }
512
513 public static function get_admin_list_template_url(){
514 return get_admin_url(null, 'edit.php?post_type=' . Template_Cpt::TYPE . Template_Cpt ::TEMPLATE_SECTION_ID);
515 }
516
517 public static function get_checkout_input_fields(string $form_type = 'billing')
518 {
519 $checkout = WC()->checkout();
520 $fields = $checkout->get_checkout_fields($form_type);
521
522 $billing_fields = [];
523
524 foreach ($fields as $key => $field) {
525 $array = ['list_key' => $key, 'list_title' => $field['label']];
526 array_push($billing_fields, $array);
527 }
528
529 return $billing_fields;
530 }
531
532 public static function order_checkout_fields($settings, $form_type = 'billing')
533 {
534 WC()->checkout()->checkout_fields = null;
535
536 add_filter("woocommerce_{$form_type}_fields", function ($fields) use ($settings) {
537 $priority = 10;
538 foreach ($settings as $input) {
539 $key = $input['list_key'];
540 if (isset($fields[$key])) {
541 $fields[$key]['priority'] = $priority;
542 $priority += 10;
543 }
544 }
545 return $fields;
546 });
547 }
548 }
549