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
- woocommerce pagination. not working when sorting used
- Using orderby with 2 meta keys
- Want to order by Meta Values (tweaking Post Order Widget)
- shortcode order for event custom post type
- Category with description and thumbnail
- How to order posts by the user_login that corresponds to a meta_value (which is a user id)?
- Query category-specific, paginated posts and allow viewer to change sort order
- query_posts with sorting on a custom datestamp
- Echo SKU in WooCommerce Conformation page [closed]
- Sort Posts with custom meta key by default which is currently set as optional
- How to output meta_key in wp_postmeta?
- WP_Query with several meta_query-statements and order by meta_value
- List CPT by menu_order with children right after parent
- Problem with meta_value order after update
- Order by meta values
- WP_Query orderby meta key/value suddely stopped working
- How to hide metaboxes in WordPress Admin on WooCommerce “Add Product” page – Remove side sortables for a specific user role
- Hide woocommerce login form
- Sorting not working with get_posts
- Custom product loop avoiding duplicates
- how to get woocommerce product id by acf field in wordpress and display product
- Woocommerece category page showing in stock product as out of stock
- Trying to link to a custom css file in a new folder
- Unable to enocde the result of wc_get_products
- Woocommerce – Remove ‘Buy Product’ Button + Make Product Thumbnails Clickable
- Increase product variation limit in woocommerce
- Issue with Woocommerce and extra field in orders data
- How to get an Array from “select” field in advanced custom fields
- WooCommerce widget “WooCommerce Products” template [closed]
- change text “free shipping” in WooCommerce [closed]
- How to get _POST variable on WooCommerce product page (form on homepage)
- How to add ajax loading icon after click add to cart button on woocommerce
- Disable add to cart button when product is out of stock
- WooCommerce add custom product_type_option
- Redirect whole website or pages to /wp-admin in wordpress