Home › Forums › WoodMart support forum › Visibility of out-of-stock items
Visibility of out-of-stock items
- This topic has 1 reply, 2 voices, and was last updated 1 year, 8 months ago by
Artem Temos.
-
AuthorPosts
-
December 3, 2023 at 4:27 pm #517986
MiraParticipantHello.
I wanted to ask to add the ability to properly display items that are not currently in stock.
When a customer visits the store page, they see the items sorted by popularity of sales, but even if they are out of stock, they are still at the top of the search. That’s how it is in the screenshot in the example.—–
Long ago I solved this via a snippet that I inserted via the Code Snippets plugin. I looked up the solution in this forum thread: https://stackoverflow.com/questions/25113581/show-out-of-stock-products-at-the-end-in-woocommerce/44597448#44597448
I inserted code like this:
/** * Sorts the Woocommerce Archive product query to push out of stock products to the end */ function _nok_order_by_stock_status( $posts_clauses, $query ) { // only change query on WooCommerce loops if ( $query->is_main_query() && ( is_product_category() || is_product_tag() || is_product_taxonomy() || is_shop() ) ) { global $wpdb; $posts_clauses['join'] .= " LEFT JOIN ( SELECT post_id, meta_id, meta_value FROM $wpdb->postmeta WHERE meta_key = '_stock_status' AND meta_value <> '' ) istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) "; $posts_clauses['orderby'] = " CASE istockstatus.meta_value WHEN 'outofstock' THEN 1 ELSE 0 END ASC, " . $posts_clauses['orderby']; } return $posts_clauses; } add_filter( 'posts_clauses', '_nok_order_by_stock_status', 2000, 2 );
——
I don’t know how well it works, or if it’s outdated. But it displays the information correctly. All items that are out of stock start displaying under the items that are in stock. But still don’t want to bloat the solutions, and not even possibly the right ones. Can you implement the correct solution in the next version of the theme?Attachments:
You must be logged in to view attached files.December 4, 2023 at 10:17 am #518082
Artem TemosKeymasterHello,
We will consider this as a feature request for our future updates. As for now, we don’t have such an option in our theme.
Kind Regards
-
AuthorPosts
- You must be logged in to create new topics. Login / Register