1and1 Help Centre Categories

print article

How to give a discount on the total order based on a coupon code

1. Create an additional field where shoppers can enter the coupon code.
Go to eShop -> Advanced Settings -> Payment methods -> Rules for the order pages
Here you should see $RULE_ORDERPAGE_2


add_field(array("fieldname" => 'discount_code',
"fieldname_text" => "Discount Code:",
"typ" => "textfield(size=18):Text (any)"
));
2. Now you have to enter a rule to give the discount.
Go to eShop -> Advanced Settings -> Payment methods -> Settings for all payment methods.
Here you should see Rule for all payment methods Enter the following code:

if (get_orderinfo_additional_field('discount_code') == '12345')
{
$additional_costs = -($total_sum * 0.05);
$text_order_additional_costs = "5% Discount coupon code";
}
A shopper is asked to enter any discount/coupon codes in the T&C page.

If the code is correct (in this case 12345), the the discount is applied.

Note: The discount is given to the amount including the tax. So for example
the tax amount was $10.00 and the total order was 500, then the discount will be
applied on £510.00

Similarly, you can give various discounts based on the coupon code entered. In the following example:
discount for '12345' is 5%
discount for '123456' is 15%
discount for '1234567' is 20%
All you have to do is include more statements:


if (get_orderinfo_additional_field('discount_code') == '12345')
{
$additional_costs = -($total_sum * 0.05);
}
elseif (get_orderinfo_additional_field('discount_code') == '123456')
{
$additional_costs = -($total_sum * 0.15);
}
elseif (get_orderinfo_additional_field('discount_code') == '1234567')
{
$additional_costs = -($total_sum * 0.20);
}
$text_order_additional_costs = "5% Discount coupon code";