I'm trying to create my own coupon type so that I can give it a name that will appear in the checkout and add features such as expiry date and product reference. I have been able to add the features to the "percentage amount" coupon type and if I only had one coupon type I'd just change the display name of that, but there will be many coupon types in my shop. Each is a one-time use coupon that a major client can give to their members so there would be types such as Ford-employee-discount and Toyota-employee-discount with individual coupons trackable to individual staff. So even the coupon code wouldn't be good enough to display because it will be something like "F_Emp-JH6d98"

So now that I have a new coupon type I have duplicated all the fields from percentage coupon type but when I get such a coupon added to a bill the "Granted amount" is blank. No discount is applied but the coupon is there on screen and listed as used by the database.

I'd prefer to be able to add a display name field to the coupon type and set it for each coupon I issue (which are made in batches by the Coupon Batch module), but without modifying the Coupon module I can't see how to display the value of that field in the right places.

1 Answer 1


You may need to implement


to add your granted amount to the display there.


 * Implements hook_commerce_coupon_granted_amount_alter
function MYMODULE_commerce_coupon_granted_amount_alter(&$amount, $coupon, $values) {

  if ($coupon->type == 'my_coupon_type') {
    $order = commerce_order_load($values->order_id);
    $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
    $coupon_wrapper = entity_metadata_wrapper('commerce_coupon', $coupon);

    // Do stuff to get amount from coupon...
    // ...
    // ...
    $amount = 1000; // example
    $currency_code = "USD";
    $amount = commerce_currency_format($amount, $currency_code, $coupon);
  • That hook does get called and it made me look into the code of the other modules where they explicitly check for their coupon type before deducting any cost. It seems a bit useless then to have UI for creating new coupon types when clearly you need a custom module to make any use of them. Better to have that module provide new coupon types I think, so I'll take that path.
    – Craig
    Commented Dec 18, 2013 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.