Created
February 28, 2018 10:24
-
-
Save iconicwp/f568ee2865bb065070969d5cd475e738 to your computer and use it in GitHub Desktop.
Add "Low Stock" badge to WooCommerce catalog products
This file contains hidden or 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
<?php | |
/** | |
* Add low stock badge. | |
*/ | |
function iconic_add_low_stock_badge() { | |
global $product; | |
$manage_stock = $product->get_manage_stock(); | |
$stock = $product->get_stock_quantity(); | |
if ( ! $manage_stock || $stock > 10 ) { | |
return; | |
} | |
?> | |
<span class="iconic-badge iconic-badge--low-stock"><?php _e( 'Low Stock', 'iconic' ); ?></span> | |
<?php | |
} | |
add_action( 'woocommerce_before_shop_loop_item', 'iconic_add_low_stock_badge', 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment