Hi,
I had a problem with the filter “WOODMART WooCommerce Layered Nav”
When I chose to show only the specific size in the filters, it also showed me the products that were out of stock.
I searched I found this code here and it worked for my website. But when I update the theme and plugins it stopped working.
I also tried to run the old theme with the old plugins locally, the code was running normally,
I only upgraded the theme without the plugins and the code stopped working.
So I assumed that in the theme update some change was made and the code did not work
I found the code from here:
https://github.com/ctuxboy/Woocommerce-out-of-stock-variations-loop
add_action( 'woocommerce_before_shop_loop_item_title', 'wk_out_of_stock_variations_loop' );
function wk_out_of_stock_variations_loop(){
global $product;
if ( $product->product_type == 'variable' ) { // if variation product is out of stock
$available = $product->get_available_variations();
if ( $available )foreach ( $available as $instockvar ) {
if ( isset($instockvar['attributes']['attribute_pa_size'] ) ) {
if ( ( $instockvar['attributes']['attribute_pa_size'] == $_GET['filter_size'] ) && (!$instockvar['max_qty']>0) ) {
global $product;
$id = $product->get_id();
echo "<style>.post-$id{display: none}</style>";
// echo '<p style="color:red;font-weight: bold;">OUT OF STOCK</p>';
}
}
}
}
if ( !$product->is_in_stock() ) { // if single product is out of stock
// echo '<p style="color:red;font-weight: bold;">OUT OF STOCK</p>';
}
}