How to calculate Free Shipping based on final Total Price in Prestashop ?

how-to-calculate-free-shipping

After reading this blog we will be able to calculate Free Shipping based on the final Total Price of the Cart.

Problem Statement

Presently, when we add products into the cart and move to the checkout section to avail of discount and shipping then we see that the discount applies after shipping.
Let’s say,

  • Cart total amount is $100 which avail Free Shipping and some discount of 5% is also added
  • Then after the discount Total Amount of the cart is set to below $100 but still, Free Shipping applies which should not happen. Free Shipping must apply to the Final Total amount of the cart after the discount.
  • This is the default process of Prestashop. Refer to the screenshot below where shipping must be Free if Order Total is > 50 but it has applied Free Shipping while Order Total is < 50 after discount –

free shipping Invoice

Recommended Read: Free Shipping Strategies: Why to Offer? How to Offer? When to Offer?

Why the current issue is there?

The current issue is there because the shipping amount is being calculated on the Order Total amount which is set into the Cart before applying the discount. You can check the lines of code below where Order Total without discount amount is being used to calculate shipping –

$shipping_cost += $carrier->getDeliveryPriceByPrice($the_total_price, $id_zone, (int)$this->id_currency);

Requirement

We need to modify the below-mentioned file to fix the same. We will be overriding the corresponding lines of the class file to avoid any changes in Core files.

Below is the list of class files which will be overridden-

1. Root dir\classes\Cart.PHP

Procedure to Solve the issue-

Follow the below-mentioned steps –

1. Rewrite function getPackageShippingCost

2. After the line given below –

// Order total in default currency without fees $order_total = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);

3. Add the following statement –

$listeDiscounts = $this-&gt;getCartRules();
$total_discounts = 0;
if (is_array($listeDiscounts)) {
if (isset($listeDiscounts[0]['value_real']))
$total_discounts = $listeDiscounts[0]['value_real'];
}
$price_to_apply_shipment = floatval($order_total) - floatval($total_discounts);

<strong>Recommended Read: </strong><a href="https://www.knowband.com/blog/opencart-blog/best-free-shipping-manager-extension-opencart-store/">Best Free Shipping Manager Extension for OpenCart Store</a>

4. Replace the lines mentioned below –

Replace this line

$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int)$id_zone, (int)$this->id_currency);

With

$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $price_to_apply_shipment, (int)$id_zone, (int)$this->id_currency);

————AND—————–

Replace this line

$shipping_cost += $carrier->getDeliveryPriceByPrice($the_total_price, $id_zone, (int)$this->id_currency);

With

$shipping_cost += $carrier->getDeliveryPriceByPrice($price_to_apply_shipment, $id_zone, (int)$this->id_currency);

5. Clear the cache and run.

Refer to the screenshot below after applying changes to the code –

free shipping Invoice-front-end

After following the above procedure, you will be able to calculate Shipping on the Final Total amount of the Cart.

Conclusion

When it comes to online buying, the whole pricing structure plays a crucial role for the customers. One of the factors that might make or break your conversions is the availability of free shipping. One method for determining the shipping options and costs on an eCommerce website is the Free shipping Manager Addon by Knowband. One of the most important requirements for increasing average sales is providing openness in the transaction.

free-shipping-testimonal

The shops that used this free shipping module boosted site traffic, revenue, and conversion rates. With the help of this free shipping plugin, store administrators can define the guidelines and conditions for shipping costs. Even better, this feature can be added or removed from the website by the store administrator.

Knowband-free-shipping-manager

The threshold over which free shipping is offered can be set by online retailers. As a result, it even encourages customers to make larger purchases in order to qualify for free shipping. To know further about the functionality of the Free Shipping Module, feel free to contact us at support@knowband.com

Leave a Reply

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