Home Forums WoodMart support forum Show Out of stock products at the end

Show Out of stock products at the end

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #257865

    Vucci
    Participant

    Hallo.
    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.

    #257911

    Artem Temos
    Keymaster

    Hello,

    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

    #257919

    Vucci
    Participant

    Thank 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.
    #257921

    Artem Temos
    Keymaster

    Hello,

    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

    #257946

    Vucci
    Participant

    thank 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.

    #257953

    Artem Temos
    Keymaster

    We are not able to enter your dashboard https://gyazo.com/266f01405f7ea894bc74079b7f1c9de1

    #257957

    Vucci
    Participant

    I’m sorry.
    I reviewed the settings.
    Do you want to put it in?

    #257969

    Artem Temos
    Keymaster

    The 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.

    #257992

    Vucci
    Participant

    thank you for your answer.
    That was the case.
    I understand.
    Thank you very much for your support.

    #258033

    Artem Temos
    Keymaster

    You are welcome! Is there anything else that I can help you with?

    #258049

    Vucci
    Participant

    All solved.
    Also, if you have any problems, we will take care of you.
    It was helpful. Thank you very much.

    #258086

    Artem Temos
    Keymaster

    Great, have a nice day!

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

The topic ‘Show Out of stock products at the end’ is closed to new replies.