I’m having a hard time to automatically hide some products based on id from shop loop, search etc if the stock drops bellow a specific number.
I’m trying to do this because I’m trying to reserve lets say 20 items from that product so they can be sold elsewhere.
functions.php
add_filter( 'pre_option_woocommerce_hide_out_of_stock_items', 'set_out_of_stock_product_qty_less_than' );
function set_out_of_stock_product_qty_less_than( $hide ) {
global $product;
$product_id = 2004891;
$product = wc_get_product($product_id);
$stock = $product->get_stock_quantity();
//$prodid = $product->get_id();
//$stock = $product->get_stock_quantity();
if ( $stock <= 174) {
$hide = 'yes';
}
return $hide;
}
2
Answers
You can hide from shop page through this hook