admin管理员组

文章数量:1130349

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();

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();

本文标签: can39t get the product id in single woocommerce page