The meta_query
argument (that you can use in a WP_Query
) is not enabled by default when using a WC_Order_Query
through wc_get_orders()
WooCommerce function.
But for you can use the undocumented Custom Field Parameters (just like in a WP_Query
):
meta_key
meta_value
meta_value_num
meta_compare
So in your case you can use the following instead:
$orders = wc_get_orders( array(
'limit' => -1, // Query all orders
'orderby' => 'date',
'order' => 'DESC',
'meta_key' => 'var_rate', // The postmeta key field
'meta_compare' => 'NOT EXISTS', // The comparison argument
));
This time it works nicely (Tested on WooCommerce 3.5.8 and 3.6.2).
Related Posts:
- Woocommerce Get Orders By Meta Value
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- Custom WP_Query order by post_meta and (author) user_meta
- WP_Query for WooCommerce Products
- Perform query with meta_value date
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- WooCommerce: filter by parent product’s taxonomy and product variation’s meta data
- how to retrieve specific product attribute value in an sql query?
- WP Query – Get WooCommerce Products with variation that is in stock
- Meta Query for specific months
- How to orderby meta_value_num with dollar ($) sign
- Extending woocommerce admin product search
- merge two query arguments into one WP_Query call
- Get all products which have both product category
- Optional Meta Query
- Overwrite YoastSEO meta-tags with another page’s [closed]
- How to orderby multiple meta fields if some fields are empty
- Extend product search with meta in WooCommerce
- Meta Query relation “AND” then set array accordingly
- How to set up hierarchical relationships without using plugins / meta query
- Multiple meta_key ordering with pre_get_posts
- Is it possible to retrieve posts depending on meta_key LIKE condition? [duplicate]
- Why doesn’t my WP Meta Query return any results?
- WP_Query meta compare must include ALL array values
- meta_query where the meta value is not the post title
- Query multiple post types, but different order for each
- ElasticPress is (aparently) messing with my search filters
- How to do WP_User_Query for Nested Array value Inside Nested Array field
- Meta query orderby meta_value_num sorting by role first
- Query against multiple locations within single custom post type post
- Strange results from WP_Query
- WP Query. Ordering posts by another post types meta
- Slow wp_posts and wp_postmeta query using Advance Custom Fields
- Query by meta value (add a dropdown of all values)
- Meta query doesn’t remove placeholder escape before query
- Create global array to compare inside a query
- What is the best way to reset a search on a meta_key / meta_value?
- How can I modify standard search query to include also ACF custom fields values?
- Using the same WP_Query for shop and widgets in WooCommerce shop
- Filter posts/pages by user_role array
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- Use meta query only 3 or more results?
- Use value from meta key array for use in WP_Query
- How to use meta_query to retrieve posts from multiple custom post type
- How to get products with the same custom attribute like ean code
- Adding arguments to WooCommerce Product Loop using AJAX
- Main loop querying current template’s info only in custom category archive pages, not my posts
- Wp_query WooCommerce products
- Show linked products using wp query and woocommerce
- Get posts by meta value except one post [closed]
- Get all user with both meta_value
- Pre_get_post on CPT archive page
- Filtering product search results using tags
- WP_Query by meta key not returning any posts
- Get posts that were most recently tagged
- ‘Active lotteries’ only custom query for woocommerce lottery plugin and elementor
- Using ‘meta_query’ with the ‘pre_get_posts()’ hook disables searching for post titles
- WordPress extremely slow when using get_posts with multiple meta_query relations
- What is the meta_query key name for the woo product average rating? [closed]
- How do I have multiple metaqueries inside one wordpress query
- How to get all post_id and meta_value using meta_key in wp_postmeta table
- WP query with multiple custom meta not respecting orderby
- Get posts using multiple values from ACF checkbox as meta query wordpress
- WP Query – Show custom posts only if user contain some user meta
- wp_query order by rand is repeating posts
- How do I subquery with custom meta fields?
- A Depth Like Parameter For “get_posts”
- get_post_meta bringing back results, but $wpdb->postmeta doesn’t
- Search query alteration not working for meta values
- Variations as Single Products [closed]
- Search results stuck on page 1
- Showing Counts on Comment List with Custom Query
- Custom query with custom filtering returning incorrect results
- Advanced Search – Is this possible?
- WP Query returning all posts when Meta_query is null
- Display only posts with thumbnails
- WP_Query (or WC_Product_Query) out of memory
- WordPress – Optimize the Meta Query for 3 meta keys at a time
- How to get posts that have certain meta key value and order based on another meta key’s value
- Passing a variable containing a comma separated list of values in a meta-query
- Complicated `orderby` based on text in custom field
- meta_query post_date not returning results
- WP Query: orderby with one meta key, but multiple values
- Filtering custom post type list in admin by custom meta key/value
- Modify WordPress Search
- Block Editor – WordPress 6.1 – CPT Archive Issue – While the title changes in the loop, all records display the same data
- $wp_query->found_posts; returns zero
- Rewrite URL custom search query
- Multiple queries and pagination
- posts_per_page showing 16 elements instead of 3
- WP_Query filtering in ACF field containing dates
- Multiple meta value orderby clauses in a WP_Query
- WP_Query: how to sort all posts by date when one category has a custom “date” field?
- Optimizing AJAX Query with Large Database
- get_meta_sql hook is not firing
- query loop “inherit query from template” prevents setting sort order
- Post Query with Meta Query no longer working
- How could i add username field in WooCommerce
- Problem making a WPQuery with ACF boolean
- Order by multiple custom fields within woocommerce hook for catalog ordering (woocommerce_get_catalog_ordering_args)