can't get the product id in single woocommerce page

admin2025-06-06  5

In the single woocommerce page where I have actions like woocommerce_before_single_product_summary to show the products, I can't access the product id. I tried the following codes and it didn't work :

$post->ID
get_the_ID()
$product->id
$product->get_id() 

In the single woocommerce page where I have actions like woocommerce_before_single_product_summary to show the products, I can't access the product id. I tried the following codes and it didn't work :

$post->ID
get_the_ID()
$product->id
$product->get_id() 
Share Improve this question asked Nov 5, 2018 at 13:51 AmiritionAmirition 3555 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

If you're using $product and $post, then you need to use global $product; and global $post to get access to them. Did you do that?

global $product;

$product_id = $product->get_id();
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749204530a317237.html

最新回复(0)