As the title says, how do i echo the stock quantity of a particular product id? Let's say the product id is "1100" and i want the stock quantity to appear in a page that is not part of the product archive. Is that possible?
For example, in an empty page, it should appear as
"Product A leftover stock: 10"
I am just learning to code and have come up with the following, but no result appear:
function nntest(){
global $woocommerce;
global $product;
$product_id = 1100;
echo $product->get_stock_quantity();
}
Thanks!
Or search for it in the plugins directory from inside your WordPress website (Plugins >> Add New) and install it. Then activate the plugin through the “Plugins” menu in WordPress. Finally, you can start using it directly at “WooCommerce > Settings > Product Quantity”.
A second option is to head over the Products page in your WordPress Admin. In this listing, you'll find the WooCommerce product ID when you hover over a product name. You can additionally search for your product using the product SKU name or product name and hover over the search results to get the Product ID.
You can use get_post_meta() function to get values from database.
this values are stored in wp_postmeta table.
$stock = get_post_meta( $post->ID, '_stock', true );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With