Hook displayProductExtraContent

Informations

Add content to the product page Adds new field / content to the FO product page
Hook displayProductExtraContent
Locations
FO
Type display
Origin core
Aliases
Description Adds new field / content to the FO product page

Located in

Origin File
classic templates/catalog/product.tpl
core src/Core/Product/ProductExtraContent.php
core src/Core/Product/ProductExtraContentFinder.php

Call of the Hook in the origin file

protected $hookName = 'displayProductExtraContent';
protected $expectedInstanceClasses = ['PrestaShop\PrestaShop\Core\Product\ProductExtraContent'];

Example implementation

This hook has been implemented as an example in our example-modules repository - demoproductextracontent.

Hook explained

This hook is a little more complicated than the other ones. It renders the provided content on the theme level. By default, it uses Bootstrap tabs to display it:

{foreach from=$product.extraContent item=extra key=extraKey}
    <div class="tab-pane fade in {$extra.attr.class}" id="extra-{$extraKey}" role="tabpanel" {foreach $extra.attr as $key => $val} {$key}="{$val}"{/foreach}>
        {$extra.content nofilter}
    </div>
{/foreach}

In the front office, ProductController fetches all extra content using a ProductExtraContentFinder.

class ProductExtraContentFinder extends HookFinder
{
    protected $hookName = 'displayProductExtraContent';
    protected $expectedInstanceClasses = ['PrestaShop\PrestaShop\Core\Product\ProductExtraContent'];

The ProductExtraContentFinder will look for modules hooked into displayProductExtraContent with the corresponding existing method, and will expect ProductExtraContent to be returned.

return (new PrestaShop\PrestaShop\Core\Product\ProductExtraContent())
    ->setTitle('example field')
    ->setContent('example content')

This content will be shown in a dedicated tab on the product page:

displayProductExtraContent