Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // WooCommerce hook to show stock level in the catalogue
- add_action('woocommerce_after_shop_loop_item_title', 'show_stock', 15);
- function show_stock() {
- global $product;
- $stock = intval($product->stock);
- switch ($stock) {
- case 0:
- $text = 'Sold';
- break;
- case 1:
- $text = 'Last one!';
- break;
- default:
- $text = "Stock: ".$stock;
- }
- echo '<span class="show_stock">'.$text.'</span>'.PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement