2

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é

R. De Caluwé
  • 43
  • 1
  • 1
  • 6

2 Answers2

6

You can get it inside Wordpress like this :

$id = $product->id;

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

EDIT (according to comment): Since WooCommerce 3, product properties should not be accessed directly, so $product->id will log a PHP error. Instead use $product->id().

Raphaël Vigée
  • 2,048
  • 14
  • 27
4

Latest method (WooCommerce 3.0.8) is $product->get_id()

tazziedave
  • 41
  • 2