I’m trying to fetch the WooCommerce products meta data using $product = new WC_Product( get_the_ID() );
I’m getting the product price and all the other values the products are downloadable WooCommerce products, I want to fetch the following data:
Whenever i try to fetch $product->downloads->id
or $product->downloads->file
i’m getting null in return. Please tell me what i’m doing wrong over here.
2
Answers
If you’re trying to get the download link, try:
This should return an array, so you can use it for example like:
To access all product downloads from a downloadable product you will use
WC_Product
get_downloads()
method.It will give you an array of
WC_Product_Download
Objects which protected properties are accessible throughWC_Product_Download
available methods (since WooCommerce 3):Related answers: