Products out of stock at the end
-
Hello! I’d like some help with this: I’ve been trying for a long time to get out of stock products to appear at the bottom of every category in my store. But I can’t. I already read several threads in the forum and the same code appears that breaks my web page. I put it directly in the functions.php file and also tried it from the code snippets plugin, and it doesn’t work. It always breaks my website.
I have templates in the “theme generator” for my store… maybe that’s why the code doesn’t work.
I need to know if there is another way to do it. Thank you very much for the help.
I copy the code that appears everywhere:
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; }
The page I need help with: [log in to see the link]
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Products out of stock at the end’ is closed to new replies.