Home Forums WoodMart support forum How to place automatically out of stock products in end end?

How to place automatically out of stock products in end end?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #508626

    cherry-wheel.com
    Participant

    I want to place off of stock in product categories at the end of product categories, I have found info about WP backery category sliders, and in that we have implement it, but such settings don’t work at main woocommerce product caterories blocks

    #508736

    Hung Pham
    Keymaster

    Hi cherry-wheel.com,

    Thanks for reaching to us.

    Add the below code to the functions.php file into the Child theme

    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,

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