I'm making an e-commerce site for a friend.

The point of his shop is to sell honey in jars. When people return the jars, they get a 2 euro discount on their next order.

I've tried several things so far but if I give the user a discount, it continues to give the discount. I only want it the discount for the next order. Same goes for other ways I've tried it. I'm not quite sure how to set these specific conditions.

3 Answers 3


Generic solution

I think you need to write some custom code to get a solution that will work automatically. This could be handled by a custom Rules condition - meaning hook_rules_condition_info() implementation. After you add the code below, make sure to add this condition through Rules interface as well. Here's example code that would go in YOUR_MODULE.rules.inc:

function YOUR_MODULE_rules_condition_info() {
  return array(
    'YOUR_MODULE_rules_condition_check_next_order_discount' => array(
      'label' => t('Sample condition'), 
      'parameter' => array(
        'order' => array(
          'label' => t('Order')
          'type' => 'commerce_order',
      'group' => t('Custom'),

function YOUR_MODULE_rules_condition_check_next_order_discount($order) {
  // Perform any checks you want here, load the owner, see previous orders, etc.
  $customer = user_load($order->uid);
  if ($whatever) {
    return TRUE;

  // I recommend doing this the other way around: by default visitors shouldn't be
  // able to have the rights for this discount, but they can get it IF they fulfill
  // your rules above.
  return FALSE;

Note: the YOUR_MODULE.rules.inc file would be loaded automatically, and you don't have to include it in the .info file of your module.

One-off solution

In case I misunderstood your question, here's how to configure the discount to have this work only once:

  1. "Apply to" fieldset, add "User" and there select the target user.

  2. Set the value of "Maximum usage per customer" field to 1.

Hope this helps.

  • It would actually not be a set rule because there are also other items than honey (for example, candles and such) which would not give a discount. So basically, I want to manually give the discount to a specific account every time I receive the jars back from them so I'm sure no discount is given for no reason.
    – wesvb
    Mar 5, 2016 at 17:38
  • Okay, then the one-off solution should work for you I think. Mar 5, 2016 at 17:42
  • Wouldn't that just allow me to do it once? Instead of every time I receive the jars from the clients?
    – wesvb
    Mar 5, 2016 at 17:56
  • Yep; to do this in a better way, you need to describe your workflow in full: is the discount always the same for all clients, can they accumulate them (e.g. someone has the right for 3 discounts), can they return to you multiple times (e.g. can they accumulate the number of orders they can get the discount on), and so on. On one hand, this sounds as an on/off flag, but at the same time it might be more complex than that (e.g. integer field where you store the number of times the user can use a discount). Hope this makes sense. Mar 5, 2016 at 18:01

I would take a different approach here, but just note that nothing that I know of would support this out of the box without additional code. The big issue is that your discount is a flat amount off of an order as opposed to an amount off of the unit price of a product, but the Commerce Discount module's order level discounts don't have the necessary conditions to set the price accordingly.

Basically, I'd add a field to the user that represents how many jars they've returned. Presumably, they might return multiple and get even more off of their next order. This field would need to be hidden from their edit form, though it's reasonable for it to appear when they view their own user profile so they know how much to expect off of their next order.

You then need to create new inline condition code in a custom module that can read this field and apply a discount if the value of the field is > 0. This is actually pretty straightforward and could be done without using Commerce Discount / inline conditions, but the problem is you really need Commerce Discount to get the $ off the order total correct.

Then for actually applying the discount to the order, you can do one of two things: you can define a new offer type that knows how to look at the user's profile to determine how large the discount should be or you can is the $ off offer type but alter the line item after the fact to be the correct amount (presumably on pre-save).

Completing the process, you need a custom rule to fire when the order is first paid in full (this is the name of the relevant event) to set the user's jar count back to 0. Not sure how you process refunds, but you'll most likely just need to reset the jar count manually in the event of a refund.


I agree with Ryan's suggestion above, however if you don't want to write custom code, I recently provided a patch for Discount Extra that allows you to use a rules component as a discount condition. You could then just write the component to check that the user has returned jars > 0 in the profile field Ryan mentioned.

The above assumes that the discount is a maximum of 2 Euro per order and not based on the number of jars they have returned. If you want it to be based on a discount for the number of jars returned (e.g 2 jars is 4 Euro discount), then you will need some custom code to look at the jar count and apply the discount accordingly.

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.