Jump to content

[TIP] Creating cart rule programmatically


Recommended Posts

The following script will create a new cart rule that can for instance be used for coupon code (voucher).


This is drawn from cart rule object model definition (classes/CartRule.php L78).

$coupon = new Discount();

//put here the coupon name + translations
//ex: if your website is in french (id language = 1) and english (id language = 2)
$coupon->name = array(1=>"mon coupon",2=>"my coupon");

//by default cart rule is valid for one client that can use it one time

$coupon->date_from = "2015-08-20";
$coupon->date_to = "2015-08-21";

$coupon->code = "789456";

//50 % off
$coupon->reduction_percent = "50";

//ex: rule only applies if the order is 100 or more including taxes and exluding shipping
$coupon->minimum_amount = 100;
$coupon->minimum_amount_tax = 1;
$coupon->minimum_amount_currency = 1;
$coupon->minimum_amount_shipping = 0;

//this creates the coupon

Hope this will help

  • Like 4
  • Thanks 1
Link to comment
Share on other sites

  • 8 months later...
  • 3 years later...
  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...