Question

I have overridden the Magento catalog phtml file in our store's custom template to display a link to a custom instructional page that we created.

enter image description here

Problem is, I only want this link to display on certain product pages.

I've noticed that on this page we have access to the variable $_product through the call to

$_product = $block->getProduct();

I've tried logging this object using print_r, etc. but nothing seems to work. How can I see the shape of this object so that I can figure out how to locate something like: $_product->category

Any advice on a better procedure to get this kind of functionality into the catalog?

Was it helpful?

Solution

To get all the data of a product you can use following.

$_product = $block->getProduct();
echo '<pre>';
print_r($_product->getData());
echo '</pre>';
die();

To get name of product you can use following for example

$_product->getName();
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top