Fix Requested Changes
Changed to check if field exists and the field is not blank.
This commit is contained in:
parent
fd33f2c2a6
commit
63b84ef407
|
@ -232,8 +232,15 @@ class WC_Data_Store_WP {
|
|||
// Check for existing values if wildcard is used.
|
||||
if ( '*' === $value ) {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
'key' => '_' . $key,
|
||||
'compare' => 'EXISTS',
|
||||
array(
|
||||
'key' => '_' . $key,
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
array(
|
||||
'key' => '_' . $key,
|
||||
'value' => '',
|
||||
'compare' => '!=',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
|
|
|
@ -1631,8 +1631,15 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
|
|||
// Check for existing values if wildcard is used.
|
||||
if ( '*' === $manual_queries['sku'] ) {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
'key' => '_sku',
|
||||
'compare' => 'EXISTS',
|
||||
array(
|
||||
'key' => '_sku',
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
array(
|
||||
'key' => '_sku',
|
||||
'value' => '',
|
||||
'compare' => '!=',
|
||||
),
|
||||
);
|
||||
} else {
|
||||
$wp_query_args['meta_query'][] = array(
|
||||
|
|
|
@ -65,11 +65,20 @@ class WC_Tests_WC_Product_Query extends WC_Unit_Test_Case {
|
|||
$results = $query->get_products();
|
||||
$this->assertEquals( 1, count( $results ) );
|
||||
|
||||
$product3 = new WC_Product_Simple();
|
||||
$product3->save();
|
||||
|
||||
// Get multiple products using wildcard.
|
||||
$query = new WC_Product_Query();
|
||||
$query->set( 'sku', '*' );
|
||||
$results = $query->get_products();
|
||||
$this->assertEquals( 2, count( $results ) );
|
||||
|
||||
// Test another field using wildcard.
|
||||
$query = new WC_Product_Query();
|
||||
$query->set( 'sale_price', '*' );
|
||||
$results = $query->get_products();
|
||||
$this->assertEquals( 2, count( $results ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue