PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.9.15
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.9.15
1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 All 163 releases
woocommerce-pos / includes / API / Traits / Query_Helpers.php

Query_Helpers.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.9.15, at includes/API/Traits/Query_Helpers.php

48 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Query_Helpers.
4 *
5 * @package WCPOS\WooCommercePOS
6 */
7
8 namespace WCPOS\WooCommercePOS\API\Traits;
9
10 use WCPOS\WooCommercePOS\Logger;
11
12 trait Query_Helpers {
13 /**
14 * Combine two meta_query arrays.
15 *
16 * @param array $meta_query1 First meta query array.
17 * @param array $meta_query2 Second meta query array.
18 *
19 * @return array Combined meta query array.
20 */
21 public function wcpos_combine_meta_queries( $meta_query1, $meta_query2 ) {
22 // If either meta_query is empty, return the other.
23 if ( empty( $meta_query1 ) ) {
24 return $meta_query2;
25 }
26 if ( empty( $meta_query2 ) ) {
27 return $meta_query1;
28 }
29
30 // Check if both meta_queries have 'AND' as their top-level relation.
31 if ( isset( $meta_query1['relation'] ) && 'AND' === $meta_query1['relation'] &&
32 isset( $meta_query2['relation'] ) && 'AND' === $meta_query2['relation'] ) {
33 // Remove the 'relation' element and combine the arrays.
34 unset( $meta_query1['relation'], $meta_query2['relation'] );
35 $combined = array_merge( $meta_query1, $meta_query2 );
36 array_unshift( $combined, array( 'relation' => 'AND' ) );
37 return $combined;
38 }
39
40 // If both meta_queries are not empty and do not both have 'AND', combine them with 'AND' relation.
41 return array(
42 'relation' => 'AND',
43 $meta_query1,
44 $meta_query2,
45 );
46 }
47 }
48