HostOnNet Blog

How to show total weight on cart in PrestaShop

Looking for Linux Server Admin or WordPress Expert? We can help.

Before modifiying template, you have to disable Cache in Admin area > Advanced parameters > Perfomance

STEP 1

Edit /src/Adapter/Presenter/Cart/CartPresenter.php

Find

 $productsTotalExcludingTax = $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS);

Add after

  $totalWeight = $cart->getTotalWeight();

Find (online 461)

 'labels' => $labels,

Add after

'total_weight' => $totalWeight,

STEP 2

Edit /themes/yourtheme/templates/checkout/_partials/cart-summary-subtotals.tpl

Find (online 38)

{/foreach}

Add after

<div class="attribute-item product-reference">
<label>{l s='Weight' d='Shop.Theme.Catalog'}</label>   
<span>{$cart.total_weight|string_format:"%.2f"} {Configuration::get('PS_WEIGHT_UNIT')}</span>
</div>

To show the weight in product page, edit themes/Yourtheme/templates/catalog/product.tpl

Find

<div class="product-availability-top mb-3">

Add after

<div class="attribute-item product-reference">
<label>{l s='Weight' d='Shop.Theme.Catalog'}</label>   
<span>{$product.weight|string_format:"%.2f"} {Configuration::get('PS_WEIGHT_UNIT')}</span>
</div>

To show in shopping cart dropdown, edit /themes/yourtheme/modules/ps_shoppingcart/ps_shoppingcart-dropdown.tpl

Find

<div class="cart-summary-line shipping-hook">
{hook h='displayCheckoutSubtotalDetails' subtotal=$cart.subtotals.shipping}
</div>
{/if}
</div>

Add after

<div class="cart-summary-subtotals">
    <div class="cart-summary-line cart-subtotal-products ">
    <label>{l s='Weight' d='Shop.Theme.Catalog'}</label>   
    <span class="price">{$cart.total_weight|string_format:"%.2f"} {Configuration::get('PS_WEIGHT_UNIT')}</span>
    </div>
</div>

Here is the final screenshot. We tested this on Pretashop 1.7.6.5, 1.7.8.6 and it is working fine.

About Sibi Antony

Bootstrap and Android LOVER. I've been creating things for the web for over 10 years, from the period of flash and table based layout web sites till mobile and tab friendly web sites.
Posted in Prestashop

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.