WC_Order_Data_Store_CPT::get_orders_generate_customer_meta_query()
Generate meta query for wc_get_orders.
Method of the class: WC_Order_Data_Store_CPT{}
No Hooks.
Return
Array
.
Usage
// private - for code of main (parent) class only $result = $this->get_orders_generate_customer_meta_query( $values, $relation );
- $values(array) (required)
- List of customers ids or emails.
- $relation(string)
- 'or' or 'and' relation used to build the WP meta_query.
Default: 'or'
WC_Order_Data_Store_CPT::get_orders_generate_customer_meta_query() WC Order Data Store CPT::get orders generate customer meta query code WC 9.4.2
private function get_orders_generate_customer_meta_query( $values, $relation = 'or' ) { $meta_query = array( 'relation' => strtoupper( $relation ), 'customer_emails' => array( 'key' => '_billing_email', 'value' => array(), 'compare' => 'IN', ), 'customer_ids' => array( 'key' => '_customer_user', 'value' => array(), 'compare' => 'IN', ), ); foreach ( $values as $value ) { if ( is_array( $value ) ) { $query_part = $this->get_orders_generate_customer_meta_query( $value, 'and' ); if ( is_wp_error( $query_part ) ) { return $query_part; } $meta_query[] = $query_part; } elseif ( is_email( $value ) ) { $meta_query['customer_emails']['value'][] = sanitize_email( $value ); } elseif ( is_numeric( $value ) ) { $meta_query['customer_ids']['value'][] = strval( absint( $value ) ); } else { return new WP_Error( 'woocommerce_query_invalid', __( 'Invalid customer query.', 'woocommerce' ), $values ); } } if ( empty( $meta_query['customer_emails']['value'] ) ) { unset( $meta_query['customer_emails'] ); unset( $meta_query['relation'] ); } if ( empty( $meta_query['customer_ids']['value'] ) ) { unset( $meta_query['customer_ids'] ); unset( $meta_query['relation'] ); } return $meta_query; }