daily pastebin goal
13%
SHARE
TWEET

WooCommerce - Show stock shortcode

lorro Oct 20th, 2015 (edited) 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // usage: Only [product_stock id="1592"] available!
  2. // code goes in functions.php for your child theme
  3. add_shortcode('product_stock', 'product_stock');
  4. function product_stock( $atts ) {
  5.   if ( ! $atts['id'] ) {
  6.     return '';
  7.   }
  8.   $product = get_product($atts['id']);
  9.   return (int) $product->get_stock_quantity(); // for WC 3.x onwards
  10. }
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
 
Top