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:
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 (6)
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.
if ( function_exists( 'AC' ) && !empty($cart_prices['salesPriceCoupon'] ) ) {
In awocoupon > installation check, make sure everything is installed. If still having issues, please post on the forum the exact issue, this blog is really old.
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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