Last active
September 9, 2015 13:54
-
-
Save ibndawood/ccf4c15323be3921f6d1 to your computer and use it in GitHub Desktop.
Displaying Stock availability like product labels
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', 'mc_make_availability_like_ribbon', 25 ); | |
function mc_make_availability_like_ribbon() { | |
global $product; | |
$availability = $product->get_availability(); | |
$stock_status = $availability['class']; | |
if( $stock_status == 'out-of-stock' ) { | |
$label = __( 'Out of Stock', 'mediacenter' ) ; | |
$label_class = 'red'; | |
} else { | |
$label = __( 'In Stock', 'mediacenter' ) ; | |
$label_class = 'green'; | |
} | |
echo '<div class="ribbon ' . esc_attr( $label_class ) . '"><span>' . $label . '</span></div>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment