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""") |