Reset only visible quantity fields to zero?

I'm using a snippet of code to reset all quantities to zero when the cart is closed, and it has worked great so far.


<script>
var FC = FC || {};
FC.onLoad = function () {
FC.client.on('cart-submit.done', function () {
jQuery("input[name$='quantity']").val(0);
});
};
</script>


But now I'm adding a gift certificate product with a user-editable price and a hidden quantity of one, and I'm wondering if there's a way to modify the script to exclude this particular product. Once the quantity resets, there's no way for the customer to add another one to the cart because the quantity field is hidden and stuck on zero. Is there a way to specify that the reset only applies to visible quantity fields and not to hidden ones? Or that it only applies to fields with a particular class? (Sorry, I know very little about javascript...)

I'm also interested in resetting the price field to value="" on this product, but I obviously don't want this to happen for my normal fixed-price products.

I'd be grateful for any advice!
Comments
  • fc_adamfc_adam FoxyCart Team
    @dustystrings,

    Ah - that would be a frustrating experience! You could use jQuery's filter() function to just get the inputs that are visible, like this:

    jQuery("input[name$='quantity']").filter(":visible").val(0);

    In terms of targeting the price input - assuming that it's also the only one that is visible, you could take the same approach.
  • @fc_adam,

    Works like a charm. Thanks so much!
Sign In or Register to comment.