Home › Forums › WoodMart support forum › Show Out of stock products at the end
Show Out of stock products at the end
- This topic has 11 replies, 2 voices, and was last updated 4 years, 1 month ago by
Artem Temos.
-
AuthorPosts
-
January 13, 2021 at 1:54 am #257865
VucciParticipantHallo.
I want to place out-of-stock products at the end.
This is different from the hiding that can be set in Woocommerce.
The setting on the shop page was solved with the following snippet/**
* Order product collections by stock status, instock products first.
*/
class iWC_Orderby_Stock_Status
{public function __construct()
{
// Check if WooCommerce is active
if (in_array(‘woocommerce/woocommerce.php’, apply_filters(‘active_plugins’, get_option(‘active_plugins’)))) {
add_filter(‘posts_clauses’, array($this, ‘order_by_stock_status’), 2000);
}
}public 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;
}
}new iWC_Orderby_Stock_Status;
However, this will not be reflected in the “ajax products tabs” installed on the top page.
Please give me advice.Thank you.
January 13, 2021 at 7:25 am #257911
Artem TemosKeymasterHello,
You don’t need to use additional code to sort products by stock status in our theme’s products elements. You can configure it with WPBakery page builder as shown on the screenshot. https://prnt.sc/wmd2vi
Kind Regards
January 13, 2021 at 7:50 am #257919
VucciParticipantThank you for your advice.
I tried the same, but the out-of-stock product is still placed second from the top.
I will send you the image.
Please check the URL sent in advance.
You can see that the second out-of-stock product is still placed from the top of the Ajax product tab placed in the middle of the site.Attachments:
You must be logged in to view attached files.January 13, 2021 at 7:52 am #257921
Artem TemosKeymasterHello,
Could you please disable all plugins that are not related to our theme and provide us your admin access so we could check it?
Thank you in advance
January 13, 2021 at 8:58 am #257946
VucciParticipantthank you for your answer.
It is not possible to disable all plugins that are not related to the theme.
The reason is that some important plugins are set up to maintain legality.
I’m sorry to say that it’s impossible.
It cannot be disabled, but we will send you an administrator code.
It would be great if you could just look at it.
If you need to disable the plugin, give it up.January 13, 2021 at 9:25 am #257953
Artem TemosKeymasterWe are not able to enter your dashboard https://gyazo.com/266f01405f7ea894bc74079b7f1c9de1
January 13, 2021 at 9:42 am #257957
VucciParticipantI’m sorry.
I reviewed the settings.
Do you want to put it in?January 13, 2021 at 10:22 am #257969
Artem TemosKeymasterThe problem is that you display best sellers products https://prnt.sc/wmgwz6
And bestsellers are products ordered by sales. That is why you can’t order them by sales and stock status at the same time. Sorry, but your solution can’t be applied here.January 13, 2021 at 11:05 am #257992
VucciParticipantthank you for your answer.
That was the case.
I understand.
Thank you very much for your support.January 13, 2021 at 12:25 pm #258033
Artem TemosKeymasterYou are welcome! Is there anything else that I can help you with?
January 13, 2021 at 1:02 pm #258049
VucciParticipantAll solved.
Also, if you have any problems, we will take care of you.
It was helpful. Thank you very much.January 13, 2021 at 2:03 pm #258086
Artem TemosKeymasterGreat, have a nice day!
-
AuthorPosts
The topic ‘Show Out of stock products at the end’ is closed to new replies.
- You must be logged in to create new topics. Login / Register