How to hide products with stock less than 2

Asked
Active3 hr before
Viewed126 times

8 Answers

products
90%

You can use a Smart collection when an Inventory Stock is greater than 1.,What is the best way to have it set up so that shopify will hide products with less than 2 items available in inventory including variations?, How to hide products less than x inventory (including variations)

 

{
   % -
   for variant in product.variants - %
} {
   % -assign sum = sum | plus: variant.inventory_quantity - %
} {
   % -endfor - %
}

{
   % -
   if sum > 1 - %
}
Show product
if the inventory_quantity is more than 1. {
   % -endif - %
}
load more v
88%

Automatically unhide the store for logged in users,WooCommerce Private Store Protected Categories,Which way of hiding WooCommerce products is right for you?

Pretag
 Pretag team - issue, fix, solve, resolve
72%

Example 4: Hide products with the lowstock status,Example 3: Show only products with the lowstock status,Example 2: Add low stock badges to products on your shop pages

In this scenario the user has unchecked the option to manage stock under Inventory > Manage Stock. Since this is the case, the user can set the stock status here to specify if a product is out of stock, in stock, on backorder, etc. We will want to add the low stock option there so it can easily be manually set per product as needed. To do this we will filter the options populated in these dropdowns using the woocommerce_product_stock_status_options filter:

/**
 * Add low stock to WooCommerce stock status options.
 */
function add_low_stock_option($options) {
   $options['lowstock'] = __('Low Stock', 'textdomain');
   return $options;
}

add_filter('woocommerce_product_stock_status_options', 'add_low_stock_option');

Now we need to account for the user managing their stock by selecting the Inventory > Manage Stock option on a product. With this option selected they can set the quantity of items they have in stock along with the low stock threshold. I will use this field as our threshold for the low stock status to be set, so there's an easy way for users to change this per product as needed. We want to make sure that we update the low stock status when the product meta is processed, so we will hook into WooCommerce's woocommerce_process_product_meta hook to make sure our custom status is added:

/**
 * Save the low stock status.
 */
function save_low_stock_status($product_id) {
   $product = wc_get_product($product_id);

   // Stock managed for product individually and between "Out of Stock" and "Low Stock Amount".
   if ($product - > get_manage_stock() &&
      ($product - > get_stock_quantity() <= $product - > get_low_stock_amount())
   ) {
      // Update to our low stock status.
      update_post_meta($product_id, '_stock_status', 'lowstock');
   }
}

add_action('woocommerce_process_product_meta', 'save_low_stock_status', 20);
load more v
65%

How to Hide Out of Stock Products in WooCommerce, How to get WooCommerce Shop URL programmatically ,There are two main ways to hide out of stock products in WooCommerce:

Pretag
 Pretag team - issue, fix, solve, resolve
75%

1.Hiding out of stock products on shop page only:,his code above was to hide out of stock products only on shop page (reference: Hide out of stock products only on shop archive pages in Woocommerce),please shed some of your guidance and knowledge to help hide out of stocks products based on product category.

this is done using the code from @loictheaztec. his code :

    add_action('woocommerce_before_add_to_cart_form', 'woocommerce_sold_out_dropdown');

    add_filter('woocommerce_product_query_meta_query', 'shop_only_instock_products', 10, 2);

    function shop_only_instock_products($meta_query, $query) {
       // Only on shop archive pages
       if (is_admin() || is_search() || !is_shop()) return $meta_query;

       $meta_query[] = array(
          'key' => '_stock_status',
          'value' => 'outofstock',
          'compare' => '!='
       );
       return $meta_query;
    }
load more v
40%

If you want less control, but a much more simple solution, you can just toggle the WooCommerce setting which will do all of this for you. Navigate to WooCommerce > Settings > Products > Inventory, and check Hide out of stock items from the catalog. Doing this will hide out of stock items everywhere on your site; in recently viewed widgets, shortcodes, search, catalog pages. Everywhere!,thank you . ive used the code in my website but there is question! products will be hide on google too ? i dont want to lose google search,Hi James, yes i'm trying check/uncheck the setting in Woocommerce, but don't work. The important thing is that it's work now ;-)You can see it here on a test webshop: https://www.youtube.com/wat...

WooCommerce changed the way visibility settings are applied to products in version 3.0.0 and above. As such, the code is slightly different to hide them from the catalog. If you’re using a version of WooCommerce greater than 3.0.0, then simply add the following snippet:

add_action('pre_get_posts', 'iconic_hide_out_of_stock_products');

function iconic_hide_out_of_stock_products($q) {

   if (!$q - > is_main_query() || is_admin()) {
      return;
   }

   if ($outofstock_term = get_term_by('name', 'outofstock', 'product_visibility')) {

      $tax_query = (array) $q - > get('tax_query');

      $tax_query[] = array(
         'taxonomy' => 'product_visibility',
         'field' => 'term_taxonomy_id',
         'terms' => array($outofstock_term - > term_taxonomy_id),
         'operator' => 'NOT IN'
      );

      $q - > set('tax_query', $tax_query);

   }

   remove_action('pre_get_posts', 'iconic_hide_out_of_stock_products');

}
load more v
22%

And when they do that, Google sees it, and it affects your SEO.,What about the traffic loss when Google de-indexes your products?,Not only that, but this keeps your items indexed in Google and other search engines, so you still appear during searches, and when they click into your store:

Pretag
 Pretag team - issue, fix, solve, resolve
60%

Building customer trust by letting customers know the time a product is available with a live countdown timer, a back in stock notification option, and the option to hide unavailable products to make for easy browsing.,Failure to track product demand or excess inventory can lead to low product turnover and storage problems, resulting in a capital loss for businesses,By setting a time duration during which the product will be available for purchase, you can manage stock and let buyers know when the product will be unavailable. With an option to get notified of the product’s availability, you don’t have to worry about missing out on sales.

Pretag
 Pretag team - issue, fix, solve, resolve

Other "products-undefined" queries related to "How to hide products with stock less than 2"