R. De Caluwé R. De Caluwé - 27 days ago 23
PHP Question

Getting the current product ID in WooCommerce

I'm using the WooCommerce plugin in Wordpress for a project that i am currently working on.

Normally, when you want to buy something (from a customer perspective) you'll add the product to the cart and buy it.

The problem is, the client I am working for doesn't want to use the cart.
Instead, he wants customers to (when they click on a product) go to a page where they'll need to fill out their name, email adress etc. and send an email for a request to buy the specific product.

But I am running into a little bit of trouble. Creating a form and sending an email is not a problem, but I need to post the current product ID to the form in order for it to work and somehow I cannot find a way to post it to the page. Is there a specific variable in which the current product ID is stored? or how do I get the product ID for me to store in a variable so I can post it to my form?

Many thanks,
René

Answer

You can get it inside Wordpress like this :

$id = $product->id;

$id = $post->id // Not working

Comments