Jump to content
Ion_Cannon

MOD/HACK/TIP: Free shipping on one carrier only.

Recommended Posts

I had the need to only have one Shipping option offer Free Shipping after the order total reached $100. In Prestashop as it is now, if you set the free shipping feature it will make all carrier selections free if the threshold is met in the cart.

With this simple little hack/mod you can make the free shipping only available for one defined carrier. In my example, I made it carrier #1 which is just Ground shipping on my site. All the other carriers except carrier "1" will still return a value for shipping when the order reaches the proper threshold. (you can change the 1 to any carrier you wish that fits your site).

MOD:

In classes/Cart.php find: "// Free fees"

AFTER

Change

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0)
         return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) AND floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
         return $shipping_cost;



To

// Added Default carrier only Free Shipping

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $id_carrier==1 AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0)
           return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $id_carrier==1 AND $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) AND floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
           return $shipping_cost;



Please test and let me know if it works out for you. Thought some might find it mildly useful. Little things sometimes make life grand. LOL

** Note: always backup any file you edit in your shop so you can roll-back. Safety tip for the day. ;)

-IC

  • Like 4

Share this post


Link to post
Share on other sites

Thank's a million for this piece of code! I wanted to do this for a long time without knowing how.

It really should be an option to put in BO by presta.

Share this post


Link to post
Share on other sites

Thanks for the code, I agree, should be part of BO.

Share this post


Link to post
Share on other sites

I agree all, it SHOULD be a built-in feature but unfortunately it's not and there are a lot of other things like this that are not that should be. I think the problem is (I'm guilty of it myself), that it can be a pretty large task to incorporate something small like this into the back office or make it a plugin when you can simply make a quick code change that takes 2 mins. I think it will ultimately be impossible to incorporate everything we all want in final versions.

Share this post


Link to post
Share on other sites

Thanks for the code It should be a part of..

Share this post


Link to post
Share on other sites

Is the anything like giving free shipping to certain group of customer? i would like to give my vip free shipping,so i would like to have one free shipping option only VIP can see. Anyone know if there is any function like that? =(

Share this post


Link to post
Share on other sites

Thanks for this hack..
I was looking for something like this for a while!

Works like a charm..

Pity Prestashop's database system just keeps adding new entry ID's for any change you make to everything..
I check my carriers and every time I made an edit, it gives it a new ID in the database.. Could get very messy in there after a while.

I even tried deleting all the existing entries in the ps_carrier table and the other carrier tables and the id still increments from the last one created despite me having deleted them all in the db.

So even though I have 4 carrier options, I'm now up to about ID#30 and had to change your code from ID=1 to ID=24.

Thanks again!

Share this post


Link to post
Share on other sites

Thank you very much.

Is there anyway I can set different free shippings?

For example:

orders over 100€ free shipping in Spain
orders over 200€ free shipping to Europe...

Thanks in advance...

Share this post


Link to post
Share on other sites

anybody can help?¿

I need to establish different free shippings depending on the country.

Pleaseeeeeeeeee

Share this post


Link to post
Share on other sites

The solution that I have been waiting for....... thanks a bunch man .... Peace no war .. heheheheheh ..

Share this post


Link to post
Share on other sites

FYI.

I just found out that this solution is not perfect.... due to how prestashop works... When ever you update your carriers the carrierid changes (incremented by 1) so when ever you make changes to your carrier please update your cart.php file with the new carrier ID ... or you can check out this other solution for free shipping... which I am going to try out...

http://www.prestashop.com/forums/viewthread/55477/#245490

Share this post


Link to post
Share on other sites

Hi,

works fine. It solved my problem too !!!

Only one annotation:
You must put the right carrier "ID" number.
In my case the desired Carrier is "SEUR", which has "ID"=35, the code will be:

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0 AND $id_carrier == 35)

You can see the carrier "ID" at the Carriers TAB in backoffice.
See the image attached in order to see where to see the carrier "ID".

Thanks for your post, great job ;-)

25777_2dk92tnz32eP5PTNZsql_t

  • Like 1

Share this post


Link to post
Share on other sites
Hi,

works fine. It solved my problem too !!!

Only one annotation:
You must put the right carrier "ID" number.
In my case the desired Carrier is "SEUR", which has "ID"=35, the code will be:

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0 AND $id_carrier == 35)

You can see the carrier "ID" at the Carriers TAB in backoffice.
See the image attached in order to see where to see the carrier "ID".

Thanks for your post, great job ;-)


Yes it does work but when ever you do a SAVE on that carrier 35 again try editing it and the carrier ID will increment to 38 or 36 but it will change so you have to change the id again in the file.....

the below works much better and when you edit your carrier you don't have to change anything

http://www.prestashop.com/forums/viewthread/55477/#245490

Share this post


Link to post
Share on other sites
Hi,

works fine. It solved my problem too !!!

Only one annotation:
You must put the right carrier "ID" number.
In my case the desired Carrier is "SEUR", which has "ID"=35, the code will be:

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0 AND $id_carrier == 35)

You can see the carrier "ID" at the Carriers TAB in backoffice.
See the image attached in order to see where to see the carrier "ID".

Thanks for your post, great job ;-)


Yes it does work but when ever you do a SAVE on that carrier 35 again try editing it and the carrier ID will increment to 38 or 36 but it will change so you have to change the id again in the file.....

the below works much better and when you edit your carrier you don't have to change anything

http://www.prestashop.com/forums/viewthread/55477/#245490


Yes, you're right. when ever I modify my that carrier, I must change the id in the file.
But the situation explained in your post, is a different situation. In that situation, you have a carrier that has free shipping from a certain order amount and another carrier that doesn’t have free shipping. This is not suitable for my needs.

You must take in mind: the free shipping range is applied to all carriers and zones is a global value, no matter how many carriers or zones do you have defined in your shop.

This could be A BETTER SOLUTION:

Near line 714 of /classes/Cart.php change:

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0 )

to:

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $orderTotal >= floatval($configuration['PS_SHIPPING_FREE_PRICE']) AND floatval($configuration['PS_SHIPPING_FREE_PRICE']) > 0 AND ($id_zone==6 OR $id_zone==18) )


Here, we are filtering by ZONES. In my case, now we say: "only apply free shipment to Spain (peninsula) and Portugal ". Any other zone will pay full shipment always.

Zones suffers less changes and modifications than carriers. It still being a temporal patch, but a better patch.

What do you think about ???


NOTE:
You must look at "(Back Office) >> Shipments >> zones" in order to see which zone "ID" do you want to filter in the code above.

25852_UkJcDW3FmqPPnD60VEcT_t

Share this post


Link to post
Share on other sites

It dosen't working the second curier donsen't show is ther any athor method to do this?

Share this post


Link to post
Share on other sites

Hi there,

COuld someone help me out for this with prestashop 1.3.1 ?

It doesn't seem to work at all for me...I could get it fixed, but then I could not get free shipping anymore for my homecountry >> or it was always free...

I want to have the following situation:
In holland above 150 euros >> Free shipping
in holland below 150 euros >> 6,75 shipping
in europe (zone made for the rest of the countries in EU) >> always pay 20 euro shipping

this is the code in my cart.php. It seems to be a bit differnent that it is described as above:

$configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
// Free fees
$free_fees_price = 0;
if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
$free_fees_price = Tools::convertPrice(floatval($configuration['PS_SHIPPING_FREE_PRICE']), new Currency(intval($this->id_currency)));
$orderTotalwithDiscounts = $this->getOrderTotal(true, 4);
if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND floatval($free_fees_price) > 0)
return $shipping_cost;
if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) AND floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
return $shipping_cost;


Could someone help me out?

Share this post


Link to post
Share on other sites

Since 2 weeks I have been using a paid module: Free Shipping Zones v0.1.3

That modules solves the problem, without getting complicated....

It is definitely worth the money (€50)

Share this post


Link to post
Share on other sites
Any one implemented this on 1.3.3? Please help!


I've done successfully by changing

this

if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND floatval($free_fees_price) > 0)
           return $shipping_cost;



to

if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND floatval($free_fees_price) > 0 AND $id_zone==6)
           return $shipping_cost;



You can use id_carrier instead of id_zone also if that's why you want.

Share this post


Link to post
Share on other sites

Hi there,

I have successfully changed this in version 1.3.6 and it works fine.

I thought, let me post it here. It might be useful to someone like me. Thanks to original poster!!

Find "// Free fees" (somewhere around 865 coding line)

Change

if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
           $free_fees_price = Tools::convertPrice(floatval($configuration['PS_SHIPPING_FREE_PRICE']), new Currency(intval($this->id_currency)));
       $orderTotalwithDiscounts = $this->getOrderTotal(true, 4);
if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND floatval($free_fees_price) > 0)
           return $shipping_cost;
if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) AND floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
           return $shipping_cost; 



To

if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
           $free_fees_price = Tools::convertPrice(floatval($configuration['PS_SHIPPING_FREE_PRICE']), new Currency(intval($this->id_currency)));
       $orderTotalwithDiscounts = $this->getOrderTotal(true, 4);
if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND $id_carrier==1 AND floatval($free_fees_price) > 0)
           return $shipping_cost;
if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $id_carrier==1 AND $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) AND floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)
           return $shipping_cost; 



Thanks.

Share this post


Link to post
Share on other sites

This MOD/HACK works fine if we want one carrier as Free shipping options if order total reached above XXX amount.

But it doesn't work with Free Shipping voucher code.

It gives all Carrier as Free Shipping options if we use Free Delivery Voucher Code.

Is there any similar HACK / MOD for it? or anyone aware of any other code changes?

Your help appreciated.

Thank You.

Share this post


Link to post
Share on other sites

How do you apply this code version 1.3.7.0 ?

I replace the code, but doesn't seem to work.

Share this post


Link to post
Share on other sites

I modded it for the version 1.4.4 this is the code

and this is around the line 1114

 

// Free fees

$free_fees_price = 0;

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $id_carrier==YOURCARRIER ID #)

$free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));

$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);

if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)

return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $id_carrier==YOURCARRIER ID # AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)

return $shipping_cost;

  • Like 2

Share this post


Link to post
Share on other sites

Perfect solution.

 

But how can we hide the msg "Remaining amount to be added to your cart in order to obtain free shipping:" so would show only to the selected $id_carrier ? Any if clause to add the $id_carrier param?

Share this post


Link to post
Share on other sites

I modded it for the version 1.4.4 this is the code

and this is around the line 1114

 

// Free fees

$free_fees_price = 0;

if (isset($configuration['PS_SHIPPING_FREE_PRICE']) AND $id_carrier==YOURCARRIER ID #)

$free_fees_price = Tools::convertPrice((float)($configuration['PS_SHIPPING_FREE_PRICE']), Currency::getCurrencyInstance((int)($this->id_currency)));

$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);

if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)

return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $id_carrier==YOURCARRIER ID # AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)

return $shipping_cost;

 

Just want to confirm that this code works for v1.4.8.2. Thanks!

 

PS. Make sure to change 2 instances of "YOURCARRIER ID #" with the actual ID number of the free carrier.

Share this post


Link to post
Share on other sites

mytheory.

 

How did you get it to work?

 

I change the code and get "HTTP-error 500 (Internal Server Error):"

 

I changed ID to the correct id of the carrier I wanted to use.

Share this post


Link to post
Share on other sites

my version for 1.4.9: in line 1174 add the following if statement

 

/// update free shipping only for home country

///

if ($id_carrier <> 1) /// add ids of carriers you want to exclude from free shipping

{

if ($orderTotalwithDiscounts >= (float)($free_fees_price) AND (float)($free_fees_price) > 0)

return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) AND (float)($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)

return $shipping_cost;

 

//////////// end free shipping for home country

}

///////

Share this post


Link to post
Share on other sites

ok guys, how about if i want to set a free shipping starts @..... for each of my carriers? for example:

Carrier#1(economy shipping) - free shipping @ $30

Carrier#2(priority shipping) - free shipping @ $60

 

I think it wont be much different than code changes discussed in this topic, but since i am not a php master i cant make it work. Any help will be welcomed.using presta1.5.3.1.

Share this post


Link to post
Share on other sites

Hi,

 

Just want to confirm that this mod works on PS v.1.5.4.1.

 

Just modify the /classes/Cart.php file.

 

HTH!

Share this post


Link to post
Share on other sites

Hi there,

 

COuld someone help me out for this with prestashop 1.3.1 ?

 

It doesn't seem to work at all for me...I could get it fixed, but then I could not get free shipping anymore for my homecountry >> or it was always free...

 

I want to have the following situation:

In holland above 150 euros >> Free shipping

in holland below 150 euros >> 6,75 shipping

in europe (zone made for the rest of the countries in EU) >> always pay 20 euro shipping

 

this is the code in my cart.php. It seems to be a bit differnent that it is described as above:

 

$configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));

// Free fees

$free_fees_price = 0;

if (isset($configuration['PS_SHIPPING_FREE_PRICE']))

$free_fees_price = Tools::convertPrice(floatval($configuration['PS_SHIPPING_FREE_PRICE']), new Currency(intval($this->id_currency)));

$orderTotalwithDiscounts = $this->getOrderTotal(true, 4);

if ($orderTotalwithDiscounts >= floatval($free_fees_price) AND floatval($free_fees_price) > 0)

return $shipping_cost;

if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) AND $this->getTotalWeight() >= floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) AND floatval($configuration['PS_SHIPPING_FREE_WEIGHT']) > 0)

return $shipping_cost;

 

 

Could someone help me out?

in ps 1.5 not work, someone can help me pls??

in ps 1.5 this is original code:

 

// Free fees
$free_fees_price = 0;
if (isset($configuration['PS_SHIPPING_FREE_PRICE']))
$free_fees_price = Tools::convertPrice((float)$configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int)$this->id_currency));
$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
if ($orderTotalwithDiscounts >= (float)($free_fees_price) && (float)($free_fees_price) > 0)
{
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More