@@ -18,7 +18,27 @@ trait QueryBuilderTrait
18
18
*/
19
19
public function get ()
20
20
{
21
- return WooCommerce::all ($ this ->endpoint , $ this ->options );
21
+ $ orders = WooCommerce::all ($ this ->endpoint , $ this ->options );
22
+
23
+ if (empty ($ this ->where )) {
24
+ return $ orders ;
25
+ }
26
+ $ filteredOrders = [];
27
+ foreach ($ this ->where as $ key => $ where ) {
28
+
29
+ foreach ($ orders as $ order ) {
30
+ $ name = $ where ['name ' ];
31
+ $ name = $ order ->$ name ;
32
+ $ operator = ($ where ['operator ' ] == '= ' ) ? $ where ['operator ' ] . "= " : $ where ['operator ' ];
33
+ $ value = $ where ['value ' ];
34
+ $ condition = "' $ name' $ operator ' $ value' " ;
35
+ if (eval ("return $ condition; " )) {
36
+ $ filteredOrders [] = $ order ;
37
+ }
38
+ }
39
+ }
40
+
41
+ return $ filteredOrders ;
22
42
}
23
43
24
44
/**
@@ -65,6 +85,15 @@ public function options($parameters)
65
85
*/
66
86
public function where (...$ parameters )
67
87
{
88
+ if (count ($ parameters ) == 3 ) {
89
+ $ where = [
90
+ 'name ' => $ parameters [0 ],
91
+ 'operator ' => $ parameters [1 ],
92
+ 'value ' => $ parameters [2 ],
93
+ ];
94
+ $ this ->where [] = $ where ;
95
+ }
96
+
68
97
if (count ($ parameters ) == 2 ) {
69
98
$ this ->options [$ parameters [0 ]] = $ parameters [1 ];
70
99
}
0 commit comments