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

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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