WooCommerce - Simple show stock shortcode

lorro Jan 27th, 2017 (edited) 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // simple show stock shortcode - only works on product page
  3. // usage: Only [show_stock] available!
  4. // code goes in functions.php for your child theme
  5. add_shortcode('show_stock', 'show_stock');
  6. function show_stock() {
  7.   global $product;
  8.   return (int) $product->get_stock_quantity(); // for WC 3.x onwards
  9. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand