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
- Add a custom field for sorting the products in a specific category WOOCOMMERCE – Second try
- Query WooCommerce orders where meta data does not exist
- Pass custom Checkout field value to Stripe gateway in WooCommerce
- How can I show an empty WooCommerce cart? [closed]
- Display File Types For Woocommerce Downloadable Products On Product Page
- Limiting woocommerce line_total decimal length
- How to select default Woocommerce category page
- Creating Product Table using Gutenberg
- I can ‘t display product images based on the label
- SKU for each product on every page
- Make this Fast and Queryable
- WooCommerce slider filter for numerical attributes
- Adding Transaction-Specific Conversion Tracking from Adwords into WooCommerce
- New field on checkout is shown but it’s not saved on the order details [closed]
- Woocommerce altered my homepage, and I can’t figure out how to revert it [closed]
- Show password while you are typing it on the “my account” login page
- /page/ is not working with a custom permalink structure (WooCommerce)
- WooCommerce Bookings Plugin Not Saving Order ID
- Where is this text in a wordpress email coming from? Want to change/remove
- Woocommerce show field in product if product-tag is “VET” else hide
- How to make a “subtitle” for each Woocommerce product
- Create Product with Woocommerce API, but Variations are not linked
- How to reduce checkout loading time of `?wc-ajax=checkout`
- Split taxonomies on different pages
- woocommerce REST api on the website’s front-end
- How can I change field values of posts before displaying
- Disable theme WooCommerce template [closed]
- WooCommerce: how to set stock per attribute on variable product
- How to display products in sidebar in 2 columns?
- Increase load-out-page speed
- WooCommerce Stucked (?) – Edit dimensions
- How to add a fixed shopping cart button on the bottom of the page?
- Woocommerce cart displays outdated prices [closed]
- Titles with thumbnails in media library
- limit all products
- Pricing Rules plugin bulk table not showing in varition of products (have 2 attributes) if single attribute its shows