However, WooCommerce store owners often need to display the stock quantity in other sections of the website, such as the homepage, a blog post, a custom pricing table, and keep the quantity dynamic so that the text changes when there is a stock change.
We can therefore build a simple shortcode, that can automatically update the output, so that you never need to worry about changing that piece of content ever again. Enjoy!
With this simple snippet, you can use the shortcode you see in the screenshot to get the stock quantity for a given product ID.
PHP Snippet: Display Stock Quantity for a Product ID Via Shortcode