woocommerce show out of stock products last

Solutions on MaxInterview for woocommerce show out of stock products last by the best coders in the world

showing results for - "woocommerce show out of stock products last"
Charlotte
27 Jan 2018
1/**
2* Sorting out of stock WooCommerce products - Order product collections by stock status, in-stock products first.
3*/
4class iWC_Orderby_Stock_Status
5{
6public function __construct()
7{
8// Check if WooCommerce is active
9if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
10add_filter('posts_clauses', array($this, 'order_by_stock_status'), 2000);
11}
12}
13public function order_by_stock_status($posts_clauses)
14{
15global $wpdb;
16// only change query on WooCommerce loops
17if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag())) {
18$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
19$posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
20$posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
21}
22return $posts_clauses;
23}
24}
25new iWC_Orderby_Stock_Status;
26/**
27* END - Order product collections by stock status, instock products first.
28*/
29
queries leading to this page
how to set out of stock on woocommerce productshow to show out of stock products in woocommercewoocommerce show out of stockget out of stock products price woocommerce wordpress functiondon 27t show out of stock products in woocommercewoocommerce product out of stock instead of call uswoocommerce show out of stock products on category pagewoocommerce out of stock show last get out of stock products woocommerce wordpresshow to show product is out of stock in woocommerceout of stock product show at lastorder product collections by stock status 2c instock products first woocommerce show out of stock productsdo not show out of stock products woocommerceout of stock products show on last on shop page woocommerce pluginproduct showing out of stock in woocommercehow to show out of stock products in last woocommerceshow out of stock products woocommercewoocommerce stock show errorwoocommerce show products with stockwoocommerce hook to show products out of stockhow to show stock with woocommercewoocommerce display out of stock productswoocommerce how to all product stock outout of stock products show last in woocommerceshow out of stock products in category list woocommerceorder out of stock to latest woocommercewoocommerce out os stock items display lastwoocommerce show out of stock products lastwoocommerce out of stock show lastout of stock to last on woocommercewoocommerce out of stock product show on latswoocommerce products showing out of stockwoocommerce products all showing out of stockget out of stock products woocommerce wordpress functionwoocommerce show out of stock products last