Addition Donation on Checkout

bridge3196bridge3196 Member
in General edited January 2009
My client would like to add a checkbox on the checkout page that would allow the user to add a set donation amount to there order. For example, user is reg. for a seminar, which cost $100, upon checkout in the custom fields, there would be a box that says something like, "Yes, I would like to donate $50 to something, something..., etc.". Once the box is checked, it would add the $50 to the total.

Is this possible?
Comments
  • lukeluke FoxyCart Team
    Possible... yes. We don't normally provide this level of support, but I honestly wanted to take on the challenge to introduce some lesser known functionality that FC has. Undocumented functionality, actually... we have two methods that allow users to override and overload existing FoxyCart methods. One is being used here: http://forum.foxycart.com/comments.php?DiscussionID=804 I took advantage of the other here.

    Add this to your checkout template after ^^checkout^^ and change the text however you like.
    ^^custom_begin^^
    <h2>Additional Information</h2>
    
    <fieldset id="fc_custom_fields">
    	<legend>Additional Information</legend>
    	<div class="fc_inner">
    		<div>
    			<h4>Add Donation?</h4>
    			<input type="checkbox" id="add_donation" name="add_donation" value="yes" />
    			<label for="add_donation">Would you like to add a donation?</label>
     
    		</div>
    	</div><!-- .fc_inner -->
    </fieldset><!-- #fc_custom_fields -->
     
    ^^custom_end^^
    

    Then, add this in the head section of your template:
    <script type="text/javascript" charset="utf-8">
    /* <![CDATA[ */
    
    function addGift() {
    	var donationAmount = 50;
    	var newTotal = parseFloat($j("#order_total").val()) + parseFloat(donationAmount);
    	if ($j("#add_donation").is(":checked")) {
    		$j("#order_total").val(FC.formatter.currency(newTotal));
    		$j("#fc_cart_foot_total td.fc_col2").html(FC.formatter.currency(newTotal,true));
    	}
    }
    
    
    $j(document).ready(function() {
    	FC.checkout.overload("updatePriceDisplay",null,"addGift");
    	$j("#add_donation").click(function() {
    		FC.checkout.updatePriceDisplay();
    	});
    });
    
    
    /* ]]> */
    </script>
    

    Again, this is definitely beyond the normal level of support we provide, but your challenge inspired me. Be sure to tell your friends about FoxyCart. When we get our JavaScript methods and API figured out, we'll document this a little further.

    Enjoy. :)
  • AWESOME! Going to implement it in the next day or two, will let you know how I make out. This is exactly what I was looking for. My client is going to be excited.
  • Could this be used to allow a coupon to be used on the actual checkout page as well?
  • lukeluke FoxyCart Team
    It wouldn't be a "coupon" in the normal sense, but you might be able to dynamically adjust the total order price based on a value supplied by the customer... but it would be some tricky programming. Hope that helps.
  • Luke,

    Just wanted to let you know that it worked out perfectly and is exactly what my client wanted. Thanks again!!!
  • I'd love to see the example of this working. Is the $50 editable to any amount?
  • fc_adamfc_adam FoxyCart Team
    @gyniferh, in the case of the script Luke created, the amount would not have been editable. You could create a text input on the checkout to allow users to input any amount they wanted with a button to 'Add the order', and when they click the button it would essentially refresh the checkout page and add the donation to the current checkout.
  • brettbrett FoxyCart Team
    Whispering some developers that could help you if you need an assist with this.
Sign In or Register to comment.