The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Simple Discount Code?

bwentebwente Member
in Help edited January 2008
I know this would not be very secure, but I think I will have small and non-technical group. I want to be able to offer a discount code to users. I have done this dynamically using a URL string. But now the clients wants to offers thse codes on the radio.

Here is my simple test. How can I get this to work?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
		<script type="text/javascript">

		function compare(form) {
			formCode =;
			myCode = "TEST";

		if (formCode != myCode) {
			alert ("\nThe entries do not match. Please re-enter.")
			return false;
			form.price.value = "2.00";
			else return true;

		<form action=""; class="foxycart" method="post" onsubmit="return compare(this)" id="cart"><input type="hidden" name="phpMyAdmin" value="fbc82b46d67e062279320c2d5bfa4a74" />
			<input type="hidden" name="name" value="A great product">
			<input type="hidden" name="price" value="5.00">
			<input type="text" name="coupon">
			<input type="submit" value="Buy It Now!">
  • lukeluke FoxyCart Team
    edited January 2008
    Quantity Discount will be available by the end of the month if you're willing to wait...

    Err.. wait, you're doing coupon codes, my bad. Got them confused.

    It seems like you just have to clean up the javascript a bit. You have an else with no if, for example. Anyone out there willing to take a shot at this one?
  • Thanks Luke.

    After some sleep and you pointer I got it fixed.
    <script type="text/javascript">
    	function compare(form) {
    		formCode =;
    		myCode = "TEST";
    		if (formCode == myCode) {
    			form.price.value = "2.00";
    			return false;
    		form.price.value = "5.00";
    			return true;

    I can't get the forum to format the code correctly... sorry.
  • lukeluke FoxyCart Team
    edited January 2008
    Glad you got it working!
  • I was just looking at this and had a question. My client and I will be running a survey in a few days and want to offer the users a discount code for completing the survey. In looking at the above script, it looks like the code "TEST" is the only coupon code, right? Meaning if the user knows the secret word, they get the discount.

    Is there a way to make this dynamic in that the code generated is automatically generated and non-reusable after the first purchase? Also, this looks like it's attached to the item, is there a way to attach it to the checkout process so it is hidden, i.e. "if cart total = +$50.00 > add option for discount code (check code against list of codes)"?

  • brettbrett FoxyCart Team
    Hey ShopGentei.
    I'd try this:
    - Use a single category for your items (if possible) (DEFAULT)
    - Duplicate your DEFAULT category, and add a price_amount discount on the _category_:
    - Once the survey is completed, set a cookie indicating so
    - On your store pages, if the cookie is present/true, set your add-to-cart links/forms to add to your new category instead of the default.

    The only issue would be if you had people add items to their cart prior to completing the survey. You might be able to work a solution using the JSON object, but it sounds like that might not be an issue with your flow.

    We'll be looking to add true coupon codes in the future. If you're ever wondering about what we're doing, or you want to voice your opinion on new feature requests, check here:
  • Thanks Brett, you're the man.

    How about this

    setup the aforementioned code (js) to subtract 5$ from total of 50$ or more on checkout.

    on the checkout page:

    If cart = +$50 add input form for coupon code
    If code correct -5$
    If not correct > err mess

    How do I do that?
Sign In or Register to comment.