Home Forums WoodMart support forum out of stock products

out of stock products

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #541134

    kalipsso3
    Participant

    is there a way for out of stock items to be last displayed like if a have 2 pages the out of stock product would be the last thing on the second page

    #541448

    Hung Pham
    Participant

    Hi kalipsso3,

    Thanks for reaching to us and take our apologies for the long delay in answering.

    Add the below code to the functions.php file into the Child theme, it will automatically place out of stock products in the end.

    add_filter('posts_clauses', 'order_by_stock_status');
    function order_by_stock_status($posts_clauses) {
        global $wpdb;
        // only change query on WooCommerce loops
        if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
            $posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta 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 <> '' " . $posts_clauses['where'];
        }
        return $posts_clauses;
    }

    Regards,

    #541713

    kalipsso3
    Participant

    Thanks alot

    #542032

    Hung Pham
    Participant

    Hi kalipsso3,

    Glad to hear your issue has been resolved. Keep us in mind for future questions and concerns, we’re always here to help!

    Regards

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘out of stock products’ is closed to new replies.