Try this.
I followed the WP_Query docs to build this.
$args = [
'meta_query' => [
'relation' => 'AND',
[
'_stock_status' => [
'key' => '_stock_status',
'compare' => 'EXISTS',
],
'_sale_price' => [
'key' => '_sale_price',
'compare' => 'EXISTS',
],
'_price' => [
'key' => '_price',
'compare' => 'EXISTS',
]
]
],
'orderby' => [
'_stock_status' => 'ASC',
'_sale_price' => 'DESC',
'_price' => 'DESC'
]
];
This will order by stock first, sale price second and price third.
There is no way to order by two or more values simultaneously, at least not that I know of or could find.
Related Posts:
- How to sort products by price ASC and place all no price products to the end? (Woocommerce)
- Multiple sorting criteries (order by)
- ORDER BY custom field value
- Sorting: custom query with orderby meta_value_num THEN by title
- WooCommerce conditional meta query
- WordPress query through Products variation stock [closed]
- WooCommerce product sorting VERY slow
- Sorting posts by multiple values, combined
- Meta query with order by another custom field
- Woocommerce change tax rate programmaticly
- How do I get the latest note on the order at woocommerce? [closed]
- Create WooCommerce new order with specific ID
- Sort orders by custom order meta – Woocommerce Orders admin page
- Filter WooCommerce Orders query with user meta data
- Woocommerce: Prevent sending of email when order is “Completed”
- WooCommerce – Multiple meta query not working
- How to orderby multiple meta fields if some fields are empty
- How to redefine the sorting of product categories by menu_order?
- how to do a processing Orders into Complete after x Minutes or x hour in WooCommerce [closed]
- WP_Query with meta_query for children
- WooCommerce quick checkout form? [closed]
- Tax Query for custom Taxonomy field
- WooCommerce order complete email logic
- WooCommerce orderby template disappears and not longer works on search page
- Sort & Display WooCommerce Product Attributes by Order
- Filtering variable WooCommerce products by stock level using meta_query
- Help ordering Post loop by two meta values
- WordPress Screwing Up ‘orderby’ => ‘meta_value_num’ in ‘pre_get_posts’
- How to get woocommerce selected variation from order object
- ORDER BY custom field value out of where clause
- Woocommerce – Problem sorting and filtering products with different tax rates by price [closed]
- Send email notifications to a defined email address depending if a product in order has a specific TAG [closed]
- Cancelled orders move to Trash automatically in Woocommerce – how to disable?
- Set both meta_query and tax_query using wp_query->set
- how can i add an additional action into woocommerce admin order page through my plugin?
- Order woocommerce products alphabetically by second word in title?
- Create a regular post for every WooCommerce order
- Next/Previous Product with custom order by price & products inside the product category [closed]
- Need to check if user has completed a woo commerce payment
- How to alter taxes amounts when updating an order
- WordPress woocommerce new order email not working
- I have 3 types of prices in WP and I need to change price for each specific user role using hooks
- Order (by ASC) posts with meta_key so posts without values are last
- Custom Email via Hook only for completed order
- Access custom meta_data in processing order email
- Create order actions from custom fields woocommerce
- Update a list of product to featured if product have meta value (Mysql not wpquery)
- how can my customers view their purchased products history like an invoice in a specific page on WordPress
- Change the customer’s name to a link on an order management page
- How to save one API response to WooCommerce order meta data
- meta_query orderby sort multiple keys
- how to change value return by _stock_status
- Add button linked to single product page on order detail page
- Using Orderby and meta_value to order natural/alphanumerical
- Woocommerce order_complete email dont send after changing order status via sql
- Conditional email recipient based off Shipping Method [closed]
- Sorting: custom query with orderby meta_value_num THEN by title
- Sort by promo code used woocommerce admin panel [closed]
- Product atributes in title of order (not in description)
- WooCommerce: Order Details Table > Add Product Meta
- Woocommerce backend sorting product drag drop by menu_order to date
- Sort by price when price is set in multiple keys
- Woocommerce admin order email customize – remove product short description
- Critical error on woocommerce checkout page
- How to get current product category ID in product archive page
- WooCommerce prices location in DB
- Why do Woocommerce templates use hooks rather than get_template_part
- How to stop a Gutenberg Block from firing multiple GET Requests?
- Hide “Delete Note” link in Order Notes Panel
- Exclude products with a stock lower than the low stock threshold from the shop loop [closed]
- wp_customize – detect post type to show/hide customizer options
- WooCommerce – Display nested list of all subcategories on archive-product.php
- Woocommerce REST API – updating an order changes custom tax calculations
- How to list all WC products by their attributes values?
- WordPress Comment Box on woocommerce product page [closed]
- Can’t remove woocommerce sidebar
- Woocommerce Slow Queries
- Should I use docker in wordpress production?
- can’t get the product id in single woocommerce page
- Php echo woocommerce price
- Different files for order details
- Multiple Schema.org markups on a single product page
- Woocommerce – Adding row to cart table
- Hide a product with a certain tag from product-category
- Custom rewrite for product variation not working
- WooCommerce show a variation both in check boxes and in a list
- I can not display meta value in extras.php and template-tags.php
- How can i get the code of Shop Page Woocommerce?
- Add shortcode to show woocommerce shipping class name on product template
- Woocommerce Get Orders By Meta Value
- Deregister dequeue JS scripts except on 1 product page
- Woocommerce Rest API: woocommerce_product_invalid_image_id
- Custom post type order by post_title
- How does one allow any customer to process any order in store on woocommerce?
- Woocommerce Child Category Permalink Structure Change
- Allow customer to choose an optional free/paid product to add to their order (and reduce stock reduced & record sale)
- How to disable the “Upgrade or Downgrade” button in “My account” of WooCommerce Subscriptions
- WooCommerce – Inconsistent Indexing of Orders
- Verify if woocommerce supports this design [closed]
- Hook for Woocommerce checkout fields