I'd like to modify/eliminate the "you saved" text/info on the Cart page when a certain attribute (or attributes) has been chosen for the product in the cart.

This is the code from uc_cart.module that appears to handle the "you saved" info:

      $totalfield = '<div class="cart-normalprice">'.uc_price($display_item['#total'], $context).'</div>';
  if ($item->list_price > $item->price) {
    $savings = $item->list_price - $item->price;
    $savings = $savings * $item->qty;
    $totalsavings += $savings;
    $totalfield .= '<div class="cart-savings">You saved '.uc_price($savings, $context).'!</div>';

And I'd like to add something like "Do not display the 'You Saved' div if Option X, Option Y, or Option Z have been chosen".

Can anyone here direct me on how to accomplish that? Or could a jquery snippet such as this provide the same "hide" functionality?

(function($) {
if ($('.item-list > li:contains("sometexthere")').length > 0) {

The "newclass" would have a CSS display:none property that would hide the cart-savings div if the item-list (attribute options listing) div contained one of the words that is only used in these options. Or, it could be flip-flopped, where the div is already hidden via CSS, and the jquery adds a new css class that unhides it via "display:block".


  • i'm looking at a 7.x and 6.x version of the latest ubercart drupal modules and I can't find this 'You Saved' functionality in the uc_cart.module file. Can you tell which version of ubercart you are running? Is this a hacked version?
    – schnippy
    Apr 1 '13 at 18:52
  • Hmmm, it might indeed be a hacked version. I inherited this site from a prior manager, and that might be a modification they set up. I have been looking into jquery methods to check the item-list div for "x" and hiding the "cart-savings" field if that check returns true, but I have not had much luck in getting that to work.
    – hockey2112
    Apr 1 '13 at 19:11
  • also - can you post your jquery code? you're probably really close on this and that may be the best option given the specific class here
    – schnippy
    Apr 1 '13 at 19:20
  • Yep, added it to the original question.
    – hockey2112
    Apr 1 '13 at 19:25

Doing this in jquery is probably going to be the quickest way to achieve this, especially since you're dealing with custom code. The jquery code you posted is close, but you need a different approach to test if the list-item contains text:

    if ($('.item-list' + ':contains("someothertext")').length != 0 ) {

Also, note I used the toggle() function here which is a quicker way to determine visibility than adding / unadding a visibility class.

You can verify the above code here: http://jsfiddle.net/JZnPq/

  • this is fantastic, and it seems to be working great! Thank you! The only issue is that if I have one product that has option X selected in the cart and another product that does not have that option selected, the presence of option X's "someothertext" causes the other product's option's "cart-savings" div to toggle as well. How can I make the toggle only apply to individual products, instead of the entire cart?
    – hockey2112
    Apr 1 '13 at 20:31
  • sure - we are probably getting a little out of scope for this question / site but in jquery one way you could do this is to modify your list-item class to have a unique id (or use a different class to distinguish) and then add a wildcard (ex. stackoverflow.com/questions/5376431/…) and use the each statement to iterate over these items. There's a couple examples at the link above that will show the basics of this.
    – schnippy
    Apr 1 '13 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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