PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.18
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.18
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 / V1 / Traits / Query_Helpers.php

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

53 lines 1.6 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\V1\Traits;
9
10 use WCPOS\WooCommercePOS\Logger;
11
12 trait Query_Helpers {
13 /**
14 * Combine two meta_query arrays.
15 *
16 * @deprecated The only caller, Customers_Controller, now has its own private
17 * wcpos_merge_meta_queries(). Kept because this trait is aliased as
18 * public API in includes/API/class-aliases.php, so callers outside
19 * this repository may still use it.
20 *
21 * @param array $meta_query1 First meta query array.
22 * @param array $meta_query2 Second meta query array.
23 *
24 * @return array Combined meta query array.
25 */
26 public function wcpos_combine_meta_queries( $meta_query1, $meta_query2 ) {
27 // If either meta_query is empty, return the other.
28 if ( empty( $meta_query1 ) ) {
29 return $meta_query2;
30 }
31 if ( empty( $meta_query2 ) ) {
32 return $meta_query1;
33 }
34
35 // Check if both meta_queries have 'AND' as their top-level relation.
36 if ( isset( $meta_query1['relation'] ) && 'AND' === $meta_query1['relation'] &&
37 isset( $meta_query2['relation'] ) && 'AND' === $meta_query2['relation'] ) {
38 // Remove the 'relation' element and combine the arrays.
39 unset( $meta_query1['relation'], $meta_query2['relation'] );
40 $combined = array_merge( $meta_query1, $meta_query2 );
41 array_unshift( $combined, array( 'relation' => 'AND' ) );
42 return $combined;
43 }
44
45 // If both meta_queries are not empty and do not both have 'AND', combine them with 'AND' relation.
46 return array(
47 'relation' => 'AND',
48 $meta_query1,
49 $meta_query2,
50 );
51 }
52 }
53