Skip to content

Instantly share code, notes, and snippets.

@harishankerr
Created September 9, 2016 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harishankerr/2a11010f90e9048dc45a0da736644aaa to your computer and use it in GitHub Desktop.
Save harishankerr/2a11010f90e9048dc45a0da736644aaa to your computer and use it in GitHub Desktop.
<?php
// usage example: Current Stock: [product_stock id="2525"]
add_shortcode('product_stock', 'product_stock');
function product_stock( $atts ) {
if ( ! $atts['id'] ) {
return '';
}
$product = get_product($atts['id']);
return (int)$product->stock; // prints 19, ie the quantity of product 2525
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment