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.
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.
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…
Assuming you get the product as an object
$product = wc_get_product( id ); echo $product->get_title();
(WC version 2.5.2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With