PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.3.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.3.0
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 4 years ago elementor-data-map.php 5 years ago helper.php 4 years ago notice.php 5 years ago
helper.php
463 lines
1 <?php
2
3 namespace ShopEngine\Utils;
4
5 use ShopEngine\Core\Builders\Action;
6 use ShopEngine\Core\Config_Handler;
7 use ShopEngine\Core\ConfigHandler;
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 conditional_enqueue_quickview($template_type = 'quick_view') {
19
20 $idd = \ShopEngine\Core\Builders\Templates::get_registered_template_id($template_type);
21
22 $tm = get_post_modified_time('U', false, $idd);
23
24 if(!empty($idd)) {
25
26 $url = Helper::get_elementor_css_uri($idd);
27
28 wp_enqueue_style('quickview-fly-' . $idd, $url, [], $tm);
29
30 /**
31 * If shop page is not designed with shopengine but quickview is then some css is missing
32 * to resolve this we are enqueueing the elementor css
33 */
34 wp_enqueue_style('elementor-frontend');
35 wp_enqueue_script('wc-add-to-cart-variation');
36 wp_enqueue_script('zoom');
37
38 /**
39 * photoswipe only load only on product single page but quickview can be load anywhere
40 * to resolve this we are enqueueing the photoswipe css, js and template
41 */
42 wp_enqueue_style('photoswipe');
43 wp_enqueue_style('photoswipe-default-skin');
44 wp_enqueue_script('photoswipe');
45 wp_enqueue_script('photoswipe-ui-default');
46 add_action( 'wp_footer', 'woocommerce_photoswipe' );
47 }
48 }
49
50 public static function get_elementor_css_uri($pid) {
51
52 global $blog_id;
53
54 $wp_upload_dir = wp_upload_dir(null, false);
55
56 $base = $wp_upload_dir['baseurl'] . '/elementor/css/';
57
58 return set_url_scheme($base . 'post-' . $pid . '.css');
59 }
60
61 public static function add_to_url($url, $param) {
62 $info = parse_url( $url );
63 $query = [];
64
65 if(isset($info['query'])){
66 parse_str( $info['query'], $query );
67 }
68 return $info['scheme'] . '://' . $info['host'] . $info['path'] . '?' . http_build_query( $query ? array_merge( $query, $param ) : $param );
69 }
70
71
72 /**
73 * Auto generate classname from path.
74 *
75 * @since 1.0.0
76 * @access public
77 */
78 public static function make_classname($dirname) {
79 $dirname = pathinfo($dirname, PATHINFO_FILENAME);
80 $class_name = explode('-', $dirname);
81 $class_name = array_map('ucfirst', $class_name);
82 $class_name = implode('_', $class_name);
83
84 return $class_name;
85 }
86
87 public static function kses($raw) {
88
89 $allowed_tags = [
90 'a' => [
91 'class' => [],
92 'href' => [],
93 'rel' => [],
94 'title' => [],
95 ],
96 'abbr' => [
97 'title' => [],
98 ],
99 'b' => [],
100 'blockquote' => [
101 'cite' => [],
102 ],
103 'cite' => [
104 'title' => [],
105 ],
106 'code' => [],
107 'del' => [
108 'datetime' => [],
109 'title' => [],
110 ],
111 'dd' => [],
112 'div' => [
113 'class' => [],
114 'title' => [],
115 'style' => [],
116 ],
117 'dl' => [],
118 'dt' => [],
119 'em' => [],
120 'h1' => [
121 'class' => [],
122 ],
123 'h2' => [
124 'class' => [],
125 ],
126 'h3' => [
127 'class' => [],
128 ],
129 'h4' => [
130 'class' => [],
131 ],
132 'h5' => [
133 'class' => [],
134 ],
135 'h6' => [
136 'class' => [],
137 ],
138 'i' => [
139 'class' => [],
140 ],
141 'img' => [
142 'alt' => [],
143 'class' => [],
144 'height' => [],
145 'src' => [],
146 'width' => [],
147 ],
148 'li' => [
149 'class' => [],
150 ],
151 'ol' => [
152 'class' => [],
153 ],
154 'p' => [
155 'class' => [],
156 ],
157 'q' => [
158 'cite' => [],
159 'title' => [],
160 ],
161 'span' => [
162 'class' => [],
163 'title' => [],
164 'style' => [],
165 ],
166 'iframe' => [
167 'width' => [],
168 'height' => [],
169 'scrolling' => [],
170 'frameborder' => [],
171 'allow' => [],
172 'src' => [],
173 ],
174 'strike' => [],
175 'br' => [],
176 'strong' => [],
177 'data-wow-duration' => [],
178 'data-wow-delay' => [],
179 'data-wallpaper-options' => [],
180 'data-stellar-background-ratio' => [],
181 'ul' => [
182 'class' => [],
183 ],
184 ];
185
186 if(function_exists('wp_kses')) { // WP is here
187 return wp_kses($raw, $allowed_tags);
188 } else {
189 return $raw;
190 }
191 }
192
193 public static function kspan($text) {
194 return str_replace(['{', '}'], ['<span>', '</span>'], self::kses($text));
195 }
196
197 public static function category_list_by_taxonomy($taxonomy = '') {
198 $query_args = [
199 'orderby' => 'ID',
200 'order' => 'DESC',
201 'hide_empty' => 1,
202 'taxonomy' => $taxonomy,
203 ];
204
205 $categories = get_categories($query_args);
206
207 return $categories;
208 }
209
210 public static function trim_words($text, $num_words) {
211 return wp_trim_words($text, $num_words, '');
212 }
213
214 public static function array_push_assoc($array, $key, $value) {
215 $array[$key] = $value;
216
217 return $array;
218 }
219
220 public static function render($content) {
221 if(stripos($content, "shopengine-has-lisence") !== false) {
222 return null;
223 }
224
225 return $content;
226 }
227
228 public static function render_elementor_content($content_id) {
229 $elementor_instance = \Elementor\Plugin::instance();
230
231 return $elementor_instance->frontend->get_builder_content_for_display($content_id);
232 }
233
234 public static function esc_options($str, $options = [], $default = '') {
235 if(!in_array($str, $options)) {
236 return $default;
237 }
238
239 return $str;
240 }
241
242 public static function img_meta($id) {
243 $attachment = get_post($id);
244 if($attachment == null || $attachment->post_type != 'attachment') {
245 return null;
246 }
247
248 return [
249 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
250 'caption' => $attachment->post_excerpt,
251 'description' => $attachment->post_content,
252 'href' => get_permalink($attachment->ID),
253 'src' => $attachment->guid,
254 'title' => $attachment->post_title,
255 ];
256 }
257
258 public static function _product_tag_sale_badge($settings = null) {
259 global $product;
260 $terms = get_the_terms(get_the_ID(), 'product_tag');
261
262 $badge_position = (isset($settings['badge_position']) && !empty($settings['badge_position'])) ? esc_attr($settings['badge_position']) : 'top-right';
263 $badge_align = (isset($settings['badge_align']) && !empty($settings['badge_align'])) ? esc_attr($settings['badge_align']) : 'horizontal';
264
265 if($product->is_on_sale() || !empty($terms)) : ?>
266 <div class="product-tag-sale-badge position-<?php echo esc_attr($badge_position); ?> align-<?php echo esc_attr($badge_align); ?>">
267 <ul>
268 <?php if(!empty($terms)) : $term = $terms[0];
269 $bg = get_term_meta($term->term_id, 'shopengine_tag_bg_color', true);
270 ?>
271 <?php if(!empty(self::_discount_percentage())) : ?>
272 <li class="badge no-link off"><?php echo '-' . esc_html(self::_discount_percentage()) . '%'; ?></li>
273 <?php endif; ?>
274 <li class="badge tag">
275 <a <?php if(!empty($bg)) : ?>style="background-color:<?php echo esc_attr($bg); ?>" <?php endif; ?>
276 href="<?php echo get_term_link($term->term_id); ?>"><?php echo esc_html($term->name); ?></a>
277 </li>
278 <?php endif;
279
280 if($product->is_on_sale()) {
281 echo "<li class='badge no-link sale'>" . esc_html__('Sale!', 'shopengine') . "</li>";
282 }
283 ?>
284 </ul>
285 </div>
286 <?php
287 endif;
288 }
289
290
291 public static function _product_image($settings = null) {
292 global $product;
293 ?>
294 <div class='product-thumb'>
295 <a href="<?php echo get_the_permalink(); ?>">
296 <?php echo woocommerce_get_product_thumbnail($product->get_id()); ?>
297 </a>
298
299 <!-- end sale date -->
300 <?php
301 if(!empty($settings['counter_position']) && $settings['counter_position'] == 'image') {
302 self::_product_sale_end_date($settings);
303 }
304 ?>
305 <!-- tag and sale badge -->
306 <?php self::_product_tag_sale_badge($settings); ?>
307
308 <!-- show group buttons -->
309 <?php
310 if(isset($settings['shopengine_group_btns']) && $settings['shopengine_group_btns'] === 'yes') {
311 ?>
312 <div class="loop-product--btns">
313 <div class="loop-product--btns-inner">
314 <?php woocommerce_template_loop_add_to_cart(); ?>
315 </div>
316 </div>
317 <?php
318 }
319 ?>
320
321 </div>
322 <?php
323 }
324
325 public static function _product_sale_end_date($settings) {
326 $date = get_post_meta(get_the_id(), '_sale_price_dates_to', true);
327 if(!empty($date)) :
328 $formatted_date = date("Y-m-d", $date);
329 $config = [
330 'days' => esc_html__('Days', 'shopengine'),
331 'hours' => esc_html__('Hours', 'shopengine'),
332 'minutes' => esc_html__('Minutes', 'shopengine'),
333 'seconds' => esc_html__('Seconds', 'shopengine'),
334 ];
335
336 ?>
337 <div data-prefix="<?php echo !empty($settings['counter_prefix']) ? $settings['counter_prefix'] : ''; ?>"
338 class="product-end-sale-timer <?php echo !empty($settings['counter_position']) ? 'counter-position-' . esc_attr($settings['counter_position']) : ''; ?>"
339 data-config='<?php echo json_encode($config); ?>'
340 data-date="<?php echo esc_attr($formatted_date); ?>"></div>
341 <?php
342 endif;
343 }
344
345 public static function _product_category($settings = null) {
346 global $product;
347
348 $terms = get_the_terms(get_the_ID(), 'product_cat');
349 $terms_count = count($terms);
350
351 if($terms_count > 0) {
352 echo "<div class='product-category'><ul>";
353 foreach($terms as $key => $term) {
354 $sperator = $key !== ($terms_count - 1) ? ',' : '';
355 echo "<li><a href='" . get_term_link($term->term_id) . "'>" . esc_html($term->name) . $sperator . "</a></li>";
356 }
357 echo "</ul></div>";
358 }
359 }
360
361 public static function _discount_percentage($settings = null) {
362 global $product;
363
364 $product_data = $product->get_data();
365 $show_tag = (isset($settings['show_tag']) && !empty($settings['show_tag'])) ? esc_attr($settings['show_tag']) : 'yes';
366 $output = '';
367 if($show_tag == 'yes' && !empty($product_data['regular_price']) && $product_data['sale_price']) {
368 $percentage = round((($product_data['regular_price'] - $product_data['sale_price']) / $product_data['regular_price']) * 100);
369
370 return $percentage;
371 }
372
373 return '';
374 }
375
376
377 public static function _product_title($settings = null) {
378 ?>
379 <h3 class='product-title'>
380 <a href="<?php echo get_the_permalink(); ?>"><?php echo get_the_title(); ?></a>
381 </h3>
382 <?php
383 }
384
385 public static function _product_rating($settings = null) {
386
387 global $product;
388 ?>
389 <div class="product-rating">
390 <?php
391 if($product->get_rating_count() > 0) {
392 woocommerce_template_loop_rating();
393 } else {
394 echo sprintf('<div class="star-rating">%1$s</div>', wc_get_star_rating_html(0, 0));
395 }
396
397 // review count
398 echo sprintf('<span class="rating-count">(%1$s)</span>', $product->get_review_count());
399 ?>
400 </div>
401 <?php
402 }
403
404
405 public static function _product_price($settings = null) {
406 ?>
407 <div class="product-price">
408 <?php woocommerce_template_single_price(); ?>
409 </div>
410 <?php
411 }
412
413 public static function _product_description($settings = null) {
414 global $product;
415 $product_data = $product->get_data($product->get_id());
416 ?>
417 <div class="prodcut-description">
418 <?php echo apply_filters('shopengine_product_short_description', $product_data['description']); ?>
419 </div>
420
421 <?php
422 }
423
424 public static function _product_buttons($settings = null) {
425 if($settings['shopengine_group_btns'] !== 'yes'): ?>
426 <div class="add-to-cart-bt">
427 <?php woocommerce_template_loop_add_to_cart(); ?>
428 </div>
429 <?php endif;
430 }
431
432
433 /**
434 * todo - check the keys for refund and cancelled [wc-cancelled, wc-refunded ]
435 *
436 * @param $product_id
437 * @param int $variation_id
438 * @return int
439 */
440 public static function get_total_sale_count($product_id, $variation_id = 0) {
441
442 global $wpdb;
443
444 $qry = 'SELECT sum(lookup.product_qty) as total FROM `'.$wpdb->prefix.'wc_order_product_lookup` as lookup';
445 $qry .=' LEFT JOIN '.$wpdb->prefix.'wc_order_stats AS stat on lookup.order_id = stat.order_id ';
446 $qry .=' WHERE `product_id` = '.intval($product_id).' and variation_id = '.intval($variation_id);
447 $qry .= ' and stat.status NOT IN (\'wc-cancelled\', \'wc-refunded\') ;';
448
449 return intval($wpdb->get_col($qry)[0] ?? null);
450 }
451
452
453 public static function is_guest_checkout_allowed() {
454
455 return 'yes' === get_option('woocommerce_enable_guest_checkout');
456 }
457
458 public static function is_login_allowed_during_checkout() {
459
460 return 'yes' === get_option('woocommerce_enable_checkout_login_reminder');
461 }
462 }
463