I need to add a gratuity to my site when user add a product to a cart. The function is the same to the ioby.org site. Each time the cart is updated we will update the gratuity on the cart. I have read the solution for this function from newsignature who developed this site but it's hard for me to using rules to do it. Anyone can help me? Thanks so much!

Here is the solution from newsignature:

Gratuity was at first going to be a tax type in the Commerce system. However, one of the requirements was to also give the user the ability to remove the gratuity if they felt that they didn’t want to cover the costs for it. Since tax isn't usually an optional item in shopping carts, the ability to remove it has not been placed in the Commerce tax module. To enable that ability, we place the gratuity into a line item that is calculated every time the cart is updated. Once again we used the Entity API to generate a new product, and this time the gratuity type that has an individual SKU, and a price that is a percentage of the order total. Another custom feature we added was to show a popup message when a user removes the gratuity, explaining to them the importance of gratuity for ioby. Since the view doesn’t discriminate between the different line items, it was necessary to use some front end javascript that handles this feature. And of course, with items being added and removed from the cart, it was necessary to change the price of the gratuity on the fly, assuming it wasn’t removed.

2 Answers 2


Have a look at the Commerce Donate module. From its project page:

This module provides a donation line item type along with a donation product and product display. This is partially based on Randy Fay's excellent screencast at http://commerceguys.com/blog/using-custom-line-items-provide-donation-fe...

It uses the Select or Other module to provide the donation amount form field. If you need to modify the default donation option values, the install the Commerce Customizable Products module in order to modify the line item type form settings.

In addition to being able to create a donation product, this module also provides a donation checkout pane, allowing customers to add a donation to their order as part of the checkout process.

Especially the last paragraph seems pretty close to the "... add a gratuity to my site when user add a product to a cart ..." (= the 1st phrase in your question).


I would use the Rules module for this, with trigger event "add item to cart" and action being "add another product to the cart", where the second product is a gratuity. You might need to use a further rule to set the price of the "gratuity" product as proportional to the original product.

If you don't need to do it separately for each item, like if it's the same percentage for all, you could apply it as if it were a tax, a (negative) discount, or a handling fee, using the relevant modules for those.

  • Thanks for your help. I tried many times without success. Thought I need to learn more about the rules module.
    – Tran Huy
    Commented Aug 27, 2012 at 4:28

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.