0

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

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();
  • I did it, and I got this error: Uncaught Error: Call to a member function get_id() on null – Amirition Nov 5 '18 at 14:18
  • Where are you putting the code? How are you hooking into woocommerce_before_single_product_summary? – Jacob Peattie Nov 5 '18 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.