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 (3)

  1. Your avatar
    seyi 3 months ago 3 months ago
    There is also an issue with minimum/maxmimum order amount not taking into account the coupon code. If using AwoCoupon, you can use this solution:
    Assuming you are using standard shipping, in the file www/plugins/vmshipment/weight_countries/weight_countries.php around line 277 is this:
    <?php
                $orderamount_cond 
    $this->testRange($cart_prices['salesPrice'],$method,'orderamount_start','orderamount_stop','order amount');
    ?>

    Comment it out and add more code like this:
    <?php
                
    //$orderamount_cond = $this->testRange($cart_prices['salesPrice'],$method,'orderamount_start','orderamount_stop','order amount');

                
    $amount $cart_prices['salesPrice'];

                if ( 
    function_exists'AC' ) && empty($cart_prices['salesPriceCoupon'] ) ) {

                    
    $awosess AC()->storediscount->get_coupon_session();

                    if ( ! empty( 
    $awosess ) ) {

                        
    $amount -= ( $awosess->product_discount $awosess->shipping_discount );

                    }

                }

                
    $orderamount_cond $this->testRange($amount,$method,'orderamount_start','orderamount_stop','order amount');
    ?>

    And that should take into account AwoCoupon discount.
  2. Default avatar
    jan448 a month ago a month ago
    This guide is totally wrong.
    First of all, the file to be changed IS NOT www/plugins/vmpayment/weight_countries/weight_countries.php
    but is
    www/plugins/VMSHIPMENT/weight_countries/weight_countries.php

    Then, the code is totally wrong.
    The site will be broken with this error: syntax error, unexpected '<'

    Please write the REAL SOLUTION!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    • Your avatar
      seyi a month ago a month ago
      Thanks for spotting the error in file location, vmpayment has been changed to vmshipment.

      As for the solution, it is very much real. I have used it and I know users that have used it also. Likely your error happens because you enter the "</?php" and "?>". Those are there to indicate it is php code but should not be entered when updating your code.

      If you are still having problems, you can forward the file to me that you edited, contact email on the contact page and happy to fix any issues.

      Regards
      Seyi