Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the product name in Woocommerce

Tags:

I want to be able to display a product title by using PHP to echo the product name by the product ID (this is to be displayed within a Page, not the product page itself). I am using Wordpress and I have a plugin for PHP so I can include PHP code using [php]echo 'example';[/php]

One product example is; http://ukcctvinstallations.co.uk/product/1-camera-residential-system-hi-res/

When I edit the product, you can see in the URL that the 'Post' = 129 so am I right in saying this is the product ID?

If anyone has a solution for this, that would be much appreciated. I am using WooCommerce.

like image 835
nsilva Avatar asked Oct 02 '14 19:10

nsilva


People also ask

How do I get my product name WooCommerce?

In WooCommerce, product details are stored in product objects that hold product data. If you want to get the name of a WooCommerce product then you will first need to create a product object then call the get_name() function on that object to retrieve the product name.

How do I find the product ID on a WooCommerce cart?

You can use directly $product_id variable of the first item in cart. 2) Using an array of product IDs (one for each item in cart). To get the 1st item product ID: $products_ids_array[0]; To get the 2nd item product ID: $products_ids_array[1]; etc…


1 Answers

Assuming you get the product as an object

$product = wc_get_product( id );  echo $product->get_title(); 

(WC version 2.5.2)

like image 164
Jared Avatar answered Oct 12 '22 01:10

Jared