Created
September 25, 2016 21:51
-
-
Save harishankerr/78d32ed7f2f266c0f625321615f78c9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Shortcode to get variation stock. usage example: Current Stock: [variation_stock id="2525"] | |
// The id being entered should be that of the variation, not the product. | |
add_shortcode('variation_stock', 'variation_stock'); | |
function variation_stock( $atts ) { | |
if ( ! $atts['id'] ) { | |
return ''; | |
} | |
$varid = $atts['id']; | |
$varobj = new WC_Product_variation($varid); | |
$stock = $varobj->get_stock_quantity(); | |
return (int)$stock; // prints 19, ie the quantity of variation 2525 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment