Get the product name in Woocommerce

nsilva picture nsilva · Oct 2, 2014 · Viewed 89.3k times · Source

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.

Answer

Jared picture Jared · Feb 18, 2016

Assuming you get the product as an object

$product = wc_get_product( id );

echo $product->get_title();

(WC version 2.5.2)