Skip to content

Instantly share code, notes, and snippets.

@ibndawood
Last active September 9, 2015 13:54
Show Gist options
  • Save ibndawood/ccf4c15323be3921f6d1 to your computer and use it in GitHub Desktop.
Save ibndawood/ccf4c15323be3921f6d1 to your computer and use it in GitHub Desktop.
Displaying Stock availability like product labels
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