Back to Top

Display custom block on cart & checkout page in Prestashop

Updated 16 May 2022

In this blog we are going to learn how to show custom block in cart summary on checkout page at front end in PrestaShop.

Sometimes we need to show some additional information or we want to display some custom block on the cart page or checkout page on the front end. So, we can achieve the same by following steps.

Let’s Do A Live Test..!!!

Firstly, We can make changes in directly on core PrestaShop tpl file to achieve your requirement. You can directly add text or HTML on your desired location in below listed files.
File Path:
/themes/classic/templates/checkout/_partials/cart-summary.tpl
/themes/classic/templates/checkout/_partials/cart-detailed-totals.tpl

By using PrestaShop hooks:

We can achieve this by registering two hooks ‘displayCheckoutSummaryTop‘ and ‘displayCheckoutSubtotalDetails‘ in custom module. You can also create a separate small module to manage things separatly.

Searching for an experienced
Prestashop Company ?
Find out More

Cart Page :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$this->registerHook('displayCheckoutSubtotalDetails'); // to show custom block on cart summary
$this->registerHook('displayCheckoutSubtotalDetails'); // to show custom block on cart summary
$this->registerHook('displayCheckoutSubtotalDetails'); // to show custom block on cart summary

After that, We need to create a function to call the tpl & assign variable to get desired content.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/**
* Function to show free shipping alert on cart page
*/
public function hookDisplayCheckoutSubtotalDetails()
{
if ('cart' == $this->context->controller->php_self) {
$this->context->smarty->assign(
array(
'message' => $this->l('Add $226.5 more to avail free shipping.'),
)
);
return $this->fetch(
'module:MODULE_NAME/views/templates/hook/TPL_FILE_NAME.tpl'
);
}
}
/** * Function to show free shipping alert on cart page */ public function hookDisplayCheckoutSubtotalDetails() { if ('cart' == $this->context->controller->php_self) { $this->context->smarty->assign( array( 'message' => $this->l('Add $226.5 more to avail free shipping.'), ) ); return $this->fetch( 'module:MODULE_NAME/views/templates/hook/TPL_FILE_NAME.tpl' ); } }
/**
* Function to show free shipping alert on cart page
*/
public function hookDisplayCheckoutSubtotalDetails()
{
    if ('cart' == $this->context->controller->php_self) {
        $this->context->smarty->assign(
            array(
                'message' => $this->l('Add $226.5 more to avail free shipping.'),
            )
        );
        return $this->fetch(
            'module:MODULE_NAME/views/templates/hook/TPL_FILE_NAME.tpl'
        );
    }
}

Now create a tpl file on this path “/views/templates/hook” to call in the above function & here is the result below. You can manage the hook positions according to your need from BackOffice.

screenshot_prestashopdemo.webkul.com_8569_2022.01.15_00_24_25

Checkout Page:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$this->registerHook('displayCheckoutSummaryTop'); // to show custom block on checkout subtotal section
$this->registerHook('displayCheckoutSummaryTop'); // to show custom block on checkout subtotal section
$this->registerHook('displayCheckoutSummaryTop');  // to show custom block on checkout subtotal section

After that, We need to create a function related to this registered hook.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
/**
* Function to show free shipping alert on checkout page
*/
public function hookDisplayCheckoutSummaryTop()
{
if ('order' == $this->context->controller->php_self) {
$this->context->smarty->assign(
array(
'message' => $this->l('Add $226.5 more to avail free shipping.'),
)
);
return $this->fetch(
'module:MODULE_NAME/views/templates/hook/TPL_FILE_NAME.tpl'
);
}
}
/** * Function to show free shipping alert on checkout page */ public function hookDisplayCheckoutSummaryTop() { if ('order' == $this->context->controller->php_self) { $this->context->smarty->assign( array( 'message' => $this->l('Add $226.5 more to avail free shipping.'), ) ); return $this->fetch( 'module:MODULE_NAME/views/templates/hook/TPL_FILE_NAME.tpl' ); } }
/**
* Function to show free shipping alert on checkout page
*/
public function hookDisplayCheckoutSummaryTop()
{
    if ('order' == $this->context->controller->php_self) {
        $this->context->smarty->assign(
            array(
                'message' => $this->l('Add $226.5 more to avail free shipping.'),
            )
        );
        return $this->fetch(
            'module:MODULE_NAME/views/templates/hook/TPL_FILE_NAME.tpl'
        );
    }
}

Here is the result below.

screenshot-prestashopdemo.webkul.com_8474-2022.01.15-00_21_19

Note:

This is a basic example in which we shows only one custom field. You can follow same for the multiple columns/fields.

Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

For any doubt contact us at support@webkul.com

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home