Okay
  Public Ticket #2070423
Hide out of stock products in related and sldiers
Closed

Comments

  •  1
    dimmisel started the conversation

    Hello gus.

    Can we somehow hide the out of stock products in Related products, in Products Carousel and in Products (your shortcodes in Visual Composer)?

    We don;t want to hide them generally from the eshop, just from these options.

    Thanks in advance

  •  1,560
    Laborator replied

    Hi there,

    Add this CSS to Custom CSS:

    .woocommerce .related.products .onsale.oos {
        display: none;
    }
    

    And the out of stock badge will be hidden from the related products only.

    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group

  •  1
    dimmisel replied

    Art, 

    we want to hide the products. To filter them out. To not load them but to load some that are in stock. 

    Can we do this?

  •  1,560
    Laborator replied

    Sorry I misunderstood you, I found this article which can help you further as it is not something related to the theme.


    Best regards,
    Laborator Team


      Documentation         Join Kalium Users Group

  •  1
    dimmisel replied

    Thanks for your answer.

    I agree that related products are not so related, except if you have any filter above the woocommerce filter to output related products in theme as we tried to edit them by code but we didn't succeed that as it seems not to override them.

    Also, the other two things I ask you are surely related to your theme as I ask you how to hide out of stock product from your shortcodes in Composer (shortcodes Products Carousel and Products).

  • dichagr replied

    Related products:

    I have already tried the code you suggested but it's not optimal as it leaves a blank spot where the out of stock product was. As a result, in some cases there are 1 or zero related products showing. I am using the 'woocommerce_output_related_products_args' hook to filter them out but it's not working as it should. It seems like aurum overrides this with its own filter which is possible because I see an option at

    laborator > theme options > shop settings > Related products count: 4 

    that may use this particular hook or something similar and overrides mine.

    Laborator shortcodes:

    My question still applies. How to hide out of stock items from Products Carousel & Products (WPbakery laborator blocks)

  • [deleted] replied

    Hi dichagr,

    Can you please add the following code in functions.php (end of file):

    function filter_out_of_stock_products_in_wc_shortcodes( $query_args ) {
    $product_visibility_term_ids = wc_get_product_visibility_term_ids();
    $query_args['tax_query'][] = array(
    array(
    'taxonomy' => 'product_visibility',
    'field' => 'term_taxonomy_id',
    'terms' => $product_visibility_term_ids['outofstock'],
    'operator' => 'NOT IN',
    ),
    );

    return $query_args;
    }

    add_filter( 'woocommerce_shortcode_products_query', 'filter_out_of_stock_products_in_wc_shortcodes' );

    This will do the trick.

  • dichagr replied

    Nice piece of code! This worked for your shortcode queries! Thank you very much

    I can still see out-of-stock items in related products section on the product page though. Can you provide a solution for this too?

  • [deleted] replied

    Hi dichagr,

    This ticket is created by another user.

    Regarding your question, kindly open a new ticket and post your request so it will be helpful for the other users to take advantage of searching them on the forum. We’re glad to help you in your new thread.

    Will set this ticket as solved from here.