Created
March 2, 2014 12:32
-
-
Save trajche/9305895 to your computer and use it in GitHub Desktop.
Woocommerce: Add product out of stock badge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting PHP Notice: Undefined variable: i