Skip to content

Instantly share code, notes, and snippets.

@trajche
Created March 2, 2014 12:32
Show Gist options
  • Save trajche/9305895 to your computer and use it in GitHub Desktop.
Save trajche/9305895 to your computer and use it in GitHub Desktop.
Woocommerce: Add product out of stock badge
add_action('woocommerce_before_shop_loop_item_title','product_out_of_stock_badge');
function product_out_of_stock_badge() {
global $woocommerce, $product, $post;
$post_id = $post->ID;
$available_variations = $product->get_available_variations();
foreach ($available_variations as $variation) {
$isinstock = $variation[is_in_stock];
if ($isinstock === true) {
$i++;
}
}
if ($i == 0) {
echo '<div class="circle">Product is out of stock</div>';
}
}
@KoolPal
Copy link

KoolPal commented Feb 7, 2020

Getting PHP Notice: Undefined variable: i

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment