Example - Free ground shipping for Coupon Code, but want the customer to still have the option to pick the quicker options from Fedex at the regular price.

Update 2023 - see Check if the customer used a coupon code, to use Customer.HasDiscountCouponCode()

You can get the customer entered Coupon Code using:  Customer.GetAttribute("DiscountCouponCode").   In an Option record's surcharge expression, use the built-in [$Name] variable to get the carrier's shipping method name and the built in [$Rate] variable to get the method's rate.  In Surcharge Expression negate the rate if the shipping option name contains the word “Ground”.

Update 2017 - see below if using version 3.90 or later, and don't add this DiscountCouponCode variable!

Update 2017-12 - nopCommerce now supports multiple coupon codes applied to the cart.  So, they now store XML in the attribute. But, also, the attribute can be the null string, and you cannot call methods (like ToLower() ) on null strings.  This is how you can create the variable:

 (Customer.GetAttribute("DiscountCouponCode") + ".").ToLower()

Or just test the condition directly:

   (Customer.GetAttribute("DiscountCouponCode") + ".").ToLower().Contains("""couponcode""")

Note the extra quotes "" on both sides of string.  The XML attribute is quoted.  In the future, we'll create a collection property to make this easier.

Update 2018-07 - Smart tip - If using a unpublished category, you can create a new product template that shows the free shipping tag

---end of update---

Add new 'Shipping Director' record - a variable to get the customer entered coupon code.  Use ' + "." ' at the end because when the customer does not enter a code, then [DiscountCouponCode] will be null, so we need to check that before applying ToLower() below, or easier is just to append the ".". *

Type

String

Name

DiscountCouponCode

Expression

Customer.GetAttribute("DiscountCouponCode") + "."

Add new 'Shipping Director' record - a variable to calculate when free ground.  For example, if the Coupon Code is "freeground." (with "." at the end):

Type

Boolean

Name

FreeGround

Expression

[DiscountCouponCode].ToLower() = "freeground."



Add new 'Shipping Director' record - an Option record to get the rate.  Use a negative surcharge.

Type

Option

Name

FedEx Free ground shipping with Coupon

Expression

true

Rate Expression

Shipping.FedEx

Surcharge Expression

[FreeGround] and [$Name].Contains("Ground") ? -[$Rate] : 0

Name Expression

[FreeGround] and [$Name].Contains("Ground") ? "Free Ground Shipping" : [$Name]

Description Expression

 



If you have many different coupon codes, then give them something common so that you can easily detect them.   For example, if you have codes "ground1", "ground2", etc., then the variable's expression could be [DiscountCouponCode].ToLower().StartsWith("ground").  Or, you could use ... .Contains("ground").   

(*We could have used ' + "" ' (empty string) above rather than ".", but all strings contain and start with the empty string)

(update 7/26/2014:

For 2.65, replace    

   Customer.GetAttribute("DiscountCouponCode")

with just

      Customer.DiscountCouponCode 

(update - 3.90 allows "Multiple discount codes", so the above will The syntax error is due to the embedded quotes in the XML in the string variable.  So, don't use a variable.  use this:

Customer.GetAttribute("DiscountCouponCode").Contains("""freeship""")

 

The quoted quotes  ' "" ' replaces using the "." before to make sure the match is not a substring.  The XML has those embedded quotes to match exactly - i.e.  <CouponCode Code="freeground" /> ). 

Add new 'Shipping Director' record - a variable to calculate when free ground.  For example, if the Coupon Code is "freeground.":

Type

Boolean

Name

FreeGround

Expression

Customer.GetAttribute("DiscountCouponCode").Contains("""freeship""")

Tags :  FreeShipping
Comments
Leave your comment
:
rsaralampi@archiversonline.com
Created on: 7/26/2014 5:25 PM
Thanks.  This is exactly what I need to do, but I keep getting the following error when I try to test it.  DiscountCouponCode; Expression=Customer.GetAttribute("DiscountCouponCode") + "."; Error=No applicable method 'GetAttribute' exists in type 'Customer'
support@nopTools.com
Created on: 7/26/2014 8:07 PM
For 2.65, replace    
   Customer.GetAttribute("DiscountCouponCode")
with just
   Customer.DiscountCouponCode
philip.patel@ebix.com
Created on: 6/11/2015 3:53 PM
I've added this to my current setup, but all the options calculate as zero. I have 3 options (standard, 2nd day, and next day). It then adds a fourth option "Free Ground Shipping". All are zero. Not sure what is wrong with my setup.

We are on nopcommerce 3.2

Thanks.
support@nopTools.com
Created on: 6/11/2015 10:09 PM
Use the TEST button on the config page and see if it works there (or whether you are getting any errors or warnings).  Be sure Shipping Director is the only Active shipping rate calculation method.
support@nopTools.com
Created on: 6/11/2015 10:16 PM
Also, be sure to turn off "Free Shipping over 'X' " in admin, and check any other free shipping; all items in cart marked free shipping, or customer role, etc.