Virtuemart Minimum Amount for Free Shipment with Coupon

Virtuemart is a great shopping cart system for Joomla CMS. No system is perfect, and Virtuemart is no exception. In this post, I will describe how to change the behavior of the Minimum amount for free shipment when a coupon code has been entered.

The Problem

You go to admin->Virtuemart->Shop->Shipping methods and setup in Shipping method using the method "VM Shipment - By weight, ZIP and countries". In the process of setting up this method, you set the " Minimum Amount for Free Shipment". Lets for example say you set it to 50, otherwise the shipping cost is 2.49.

Then in the front end, the customer adds an item to the cart that costs over 50, but at the same time enters a coupon code which brings the product total under 50. Virtuemart still gives free shipping.

This happens regarless if if you are using AwoCoupon or the core Virtuemart coupons. The problem is the total used by Virtuemart to determine if the customer receives free shipping or not does not include the coupon discount.



The solution

In order to fix this problem, alterations have to be made to the shipping method code. To select the file to alter, you would have to first determine what shipping method you are using to give free shipping. If using "VM Shipment - By weight, ZIP and countries", then you would want to alter the file:

www/plugins/vmpayment/weight_countries/weight_countries.php

In this case, the shipping method is weight_countries/weight_countries.php

Around line 200, you should see the line:
<?php
if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
?>

If you are using Virtuemart 2.0.24 or above, then you would change the above to:
<?php
//if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
$amount $this->getCartAmount($cart_prices);
if (
$method->free_shipment && $amount >= $method->free_shipment) {
?>

If you are using Virtuemart 2.0.22 or less, then you would change the above to:
<?php
//if ($method->free_shipment && $cart_prices['salesPrice'] >= $method->free_shipment) {
if(empty($cart_prices['salesPrice'])) $cart_prices['salesPrice'] = 0.0;
$cartPrice = !empty($cart_prices['withTax'])? $cart_prices['withTax']:$cart_prices['salesPrice'];
if(empty(
$cart_prices['salesPriceShipment'])) $cart_prices['salesPriceShipment'] = 0.0;
if(empty(
$cart_prices['salesPriceCoupon'])) $cart_prices['salesPriceCoupon'] = 0.0;
$amount$cartPrice $cart_prices['salesPriceShipment'] + $cart_prices['salesPriceCoupon'] ;
if (
$amount <= 0$amount=0;
if (
$method->free_shipment && $amount >= $method->free_shipment) {
?>

After making that change and refreshing the cart, shipping should now be charged if the cart total, including coupon discounts is less than 50, and not charged if greater than 50.

Comments