Home Forums WoodMart support forum Menu for product categories not showing on shop page Reply To: Menu for product categories not showing on shop page

#535343

Hello,

Please add below Custom Code to the functions.php file in your child theme. This code shows your out-of-stock product at the end of the archive pages.

if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
    add_filter('posts_clauses', 'order_by_stock_status', 2000);
}

function order_by_stock_status($posts_clauses) {
    global $wpdb;

    if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag())) {
        $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta AS istockstatus ON ($wpdb->posts.ID = istockstatus.post_id)";
        $posts_clauses['orderby'] = "istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
        $posts_clauses['where'] .= " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' ";
    }

    return $posts_clauses;
}

Best Regards.