PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 1.3.1
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v1.3.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 / core / query-modifier.php
shopengine / core Last commit date
builders 4 years ago elementor-controls 4 years ago export-import 4 years ago page-templates 4 years ago register 4 years ago sample-designs 4 years ago settings 4 years ago query-modifier.php 4 years ago template-cpt.php 4 years ago
query-modifier.php
96 lines
1 <?php
2
3 namespace ShopEngine\Core;
4
5 use ShopEngine\Traits\Singleton;
6
7 class Query_Modifier
8 {
9
10 use Singleton;
11
12 public function init() {
13
14 add_action('pre_get_posts', [$this, 'modify_query']);
15 }
16
17 public function modify_query($query) {
18
19 if(is_admin() || !$query->is_main_query() || $query->is_single === true) {
20 return;
21 }
22
23 if(!isset($query->query_vars['wc_query']) || $query->query_vars['wc_query'] != 'product_query') {
24 return;
25 }
26
27 // query filter begins
28
29 // update query for product per page filter
30 if(!empty($_GET['shopengine_products_per_page'])) {
31 $query->set('posts_per_page', absint($_GET['shopengine_products_per_page']));
32 }
33
34 //update query if query param has color filter
35 foreach($_GET as $key => $vals) {
36
37 $prefix = 'shopengine_filter_color_';
38
39 if(strpos($key, $prefix) !== false) {
40
41 $tax = str_replace($prefix, '', $key);
42
43 $query->set(
44 'tax_query',
45 [
46 'relation' => 'OR',
47 [
48 'taxonomy' => $tax,
49 'field' => 'slug',
50 'terms' => $vals,
51 'operator' => 'IN',
52 ],
53 ]
54 );
55 }
56 }
57
58 //update query if query param has size filter
59 if(!empty($_GET['shopengine_filter_size'])) {
60
61 $size_values = explode(',', $_GET['shopengine_filter_size']);
62
63 if( is_array($size_values) && !empty($size_values) ){
64 $query->set('tax_query', [
65 [
66 'taxonomy' => 'pa_size',
67 'field' => 'slug',
68 'terms' => $size_values,
69 'operator' => 'IN',
70 ]
71 ]);
72 }
73 }
74
75 //update query if query param has category filter
76 if(!empty($_GET['shopengine_filter_category'])) {
77
78 $category_values = explode(',', $_GET['shopengine_filter_category']);
79
80 if( is_array($category_values) && !empty($category_values) ){
81 $query->set('tax_query', [
82 [
83 'taxonomy' => 'product_cat',
84 'field' => 'slug',
85 'terms' => $category_values,
86 'operator' => 'IN',
87 ]
88 ]);
89 }
90 }
91
92
93 // query filter ends
94 }
95 }
96