• Resolved shashikant91

    (@shashikant91)


    Hi Team,

    Need some help here on our website http://www.pcstudio.in

    We have more number of out of stock products which we wanted to show them at the end of bottom of the page/archive on the shop/archive page.

    We wanted to show the out of stock products (not hide from dashboard) but show them at the end or at a later page of the archive page.

    Example: When shop/archive page is opened the most recent & out of stock products to be shown & then out of stock products.

    Let me know if this is possible & if so how?

    Thanks & Regards
    Shashikant

Viewing 4 replies - 1 through 4 (of 4 total)
  • André

    (@chiape)

    Hi @shashikant91! How’s it going today?

    Yes, you can do it! There’s a great discussion about it in the links below, and you can also find some snippets to use.

    Here and Here!

    Also, make sure that the option to hide the out-of-stock products is unchecked from your WooCommerce settings.

    You can find it via: WordPress Dashboard > WooCommerce > Settings > products > Invetory.

    Image link if needed: https://snipboard.io/lEGb64.jpg

    I hope it helps and let us know how it goes!

    My very best,

    Hi @shashikant91,

    I found a snippet of code that works well for me. You can add this in your child theme’s functions.php file :

    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 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;
    }

    I hope this is helpful!

    Thread Starter shashikant91

    (@shashikant91)

    Hi @kaavyaiyer

    Thank you so much for the code snippet. Appreciate your help!

    I hope this works along with the sorting option – sort by latest products. Currently we are having this as our default option – sorting by latest products.

    Thanks
    Shashikant

    Hi @shashikant91

    I hope the snippet has worked out for you. I’m going to mark this thread as resolved now. If you have a few minutes, we’d love if you could leave us a review: https://wordpress.org/support/plugin/woocommerce/reviews/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show Out of Stock Items at the end/bottom’ is closed to new replies.