Subscribe via RSS

Virtuemart Free Shipping For Shopper Group

Today I searched how to allow free shipping for a specific shopper group in the Virtuemart shopping cart. There was a shopper group extension in development for this, but it does not work with our 1.1 version of Virtuemart.

I decided to dive into the source code and tackle the problem on my own. Below are the details of how to implement this on your Virtuemart system should you have need.

The first thing I did was added a column to the shopper group table. This will flag the shopper group to have free shipping in the cart if you so desire.

/*You may have to alter the table name if your prefix does not start with jos_vm_ which is the default*/
ALTER TABLE `jos_vm_shopper_group` ADD COLUMN `shopper_group_freeshipping` TINYINT(1) UNSIGNED AFTER `default`;

There is on PHP file that must be edited. It is located in the following folder under your Joomla installation directory.
\administrator\components\com_virtuemart\classes\ps_checkout.php

At or around line 63 you will see the following if statement

if($vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) {

That line needs to be replaced with the following

		$db = new ps_DB();
		$q = 'SELECT shopper_group_freeshipping from #__{vm}_shopper_vendor_xref xref
			inner join #__{vm}_shopper_group shopper on xref.shopper_group_id = shopper.shopper_group_id
			where xref.user_id = ' . $_SESSION['auth']["user_id"];

		$db->query($q);
		$db->next_record();
		$free_shoppergroup_shipping = $db->f('shopper_group_freeshipping') == 1;
		//original line at 63
		if(($vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) || $free_shoppergroup_shipping) {

A little bit further down there is this if statement

if(empty($_REQUEST['ship_to_info_id']) && ps_checkout::noShipToNecessary()) {

$db = new ps_DB();

You can comment out or remove the $db = new ps_DB();. It is now already being instantiated due to our new code.

There is nothing else that needs to be changed. You will have to manually flag shopper groups in the db using the new shopper_group_freeshipping column that was added. This should have a value of 1 for any shopper groups that need to get free shipping. All other groups can have a value of NULL or 0 to get the standard shipping you have configured in your installation.

I will make another post if I tackle adding a checkbox on the shopper group to update this field. If anyone else does it please let me know and I will post your code or provide a link to your blog.