Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #773229

    Hi ^^

    How can I Hide ‘out of stock’ products in Woocommerce ?

    Thanks!

    #773232

    Hey Ganubis,

    Please try adding following code to Functions.php file in Appearance > Editor

    add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    function custom_pre_get_posts_query( $q ) {
    
    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;
    if ( ! is_admin() ) {
    
    
    $q->set( 'meta_query', array(array(
        'key'       => '_stock_status',
        'value'     => 'outofstock',
        'compare'   => 'NOT IN'
    )));
    
    }
    
    remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    Best regards,
    Yigit

    #773259

    Thanks Yigit!
    It has not worked for me. any other idea? thank you very much :)

    #773262

    Hey!

    Please go to WooCommerce > Settings > Products > Inventory and check “Hide out of stock items from the catalog” :)

    Regards,
    Yigit

    #773518

    Thanks Yigit!
    I have tried it but it does not work for me, any other ideas please?
    Thanks

    #773754

    Hi,

    This link should help you: https://docs.woocommerce.com/document/configuring-woocommerce-settings/ – just find by “out of stock” on the page.

    Best regards,
    John Torvik

    #773862

    Thanks John!
    I have tried it (hide out of stock items from catalog) on WooCommerce > Settings > hide out of stock. but it does not work, any other ideas please?
    Thanks

    #774982

    Hi Ganubis,

    You might want to ask this question at WooCommerce support forum.

    If you need further assistance please let us know.

    Best regards,
    Victoria

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.