I'm using Drupal 7 and Drupal Commerce Module. I'd like to be able to provide customized links with promo codes in them (promo codes would be a key/value pair in a format like www.url.com/?promo=specialK or some such thing). So Group A, for example, would get their link and click on it and it would bring them to our Registration/Product page form.

This would be the same form for every group with different discounts applied to the product price depending on the promo code attached to the URL.

If the promo is expired I'd like Drupal to just give the user a page that says something like 'Your promo is expired. Sorry. blah blah blah.' However, if the promo is NOT expired it would just apply the discount to the price and let them fill out the rest of the form and submit their payment information, etc > the normal drupal commerce procedure with the discount applied.

I'm thinking of approaching this with Drupal Coupon module to enable the discounting functionality, but I don't know if it's possible to use a URL to pass that promo code automatically to Commerce. Does anyone know?

1 Answer 1


There are a number of ways you could do this. Probably the best way is to use a custom module, define a menu path with a token, and do it all in PHP. But I live mostly in the GUI world. You could also do this using Rules.

I have done something similar in a 10 minute youtube video that describes how to use rules to construct a url that passes in information and does things (like adding a product to a cart, or in your case you could use it to add a discount/apply a coupon).

Video: Using Rules to create a url to add a product to cart

Step by Step

  1. Download Rules URL Arguments

  2. Create a rule that fires on the event "Drupal is initializing"

  3. Add a "Text Comparison" condition. Compare the site:current-page:path token against your first parameter "promo" for a url like "test.com/promo?coupon=123"

  4. Add all of the actions you need to react to the rest of the parameters. In the video you'll see how to get at those parameters in the url.

  • Very nice - the video was helpful too. Now I just need to figure out how to show the form if the promo matches values in a list and to show another page if the promo is outdated.
    – Sage
    Commented Feb 4, 2016 at 21:09
  • Install inline conditions (drupal.org/project/inline_conditions) and you can do if/else inside the action of a rule which would let you use the System's Send to a page function based on a single condition. That condition might have to be a custom rule condition, but that's easy enough.
    – joshmiller
    Commented Feb 5, 2016 at 12:47

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.