@@ -18,7 +18,27 @@ trait QueryBuilderTrait
1818 */
1919 public function get ()
2020 {
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 ;
2242 }
2343
2444 /**
@@ -65,6 +85,15 @@ public function options($parameters)
6585 */
6686 public function where (...$ parameters )
6787 {
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+
6897 if (count ($ parameters ) == 2 ) {
6998 $ this ->options [$ parameters [0 ]] = $ parameters [1 ];
7099 }
0 commit comments