Prestashop 1.7.1 | Set shipping cost as a percentual of total shopping cart

This time i need to add a feature to prestashop for set shipping cost as a percentual of total shopping cart.

Our customer, wants that , if cart is under 500€ , shipping cost are equal to 10% of shopping cart amount, else shipping is free.

First set free shipping, go on Admin -> Shipping -> Preferences, and set amount on Shipping Options.

Second, we need to override the Cart.php class.

Download and open Cart.php from /classes folder

Immediately after

$shipping_cost = (float)Tools::ps_round((float)$shipping_cost, 2);

comment this line

//Cache::store($cache_id, $shipping_cost);

and add

$shipping_cost = 0; // set shipping cost to 0
$orderTotal = $order_total; // Retrive total order value
$pctShipping = .10; //whatever you want your percentage to be
$shipping_cost = floatval($orderTotal * $pctShipping); // Calculate the shipping cost
Cache::store($cache_id, $shipping_cost); // Set new shipping cost in cache

Save the file and upload with ftp on:

/override/classes

** Important, the file must have name Cart.php
** Important don’t rewrite Cart.php that you find in /classes folder, because if you update something it will be rewrite.

That’s all.