Contact Form 7 Issues Tricks and Solution

Promo Code or Coupon Code field in Contact Form 7 or changing value based on specific key typed

Few days ago one of my client requested me to implement a promo code field ( screenshot attached) in payment form (which i helped him created using contact form 7) to show a discounted price. I helped him implemented this and sharing you the code.

Procedure

  1. Here is the Contact form 7 field to use
[text couponcode placeholder "Promo Code"]

<span class="discountedPrice"> </span>

2. Here is the jQuery code ( Use Simple Custom CSS and JS plugins for this)

jQuery(document).ready(function(){
 
  
     jQuery('input[name="couponcode"]').on('input keyup', function(e){	
 
	let couponcode= jQuery( 'input[name="couponcode"]' ).val().trim(); 
       
if(couponcode=="ab123"){
	   jQuery('span.discountedPrice').html("$100");
	   }

         if(couponcode=="BC9287"){
	   jQuery('span.discountedPrice').html("$499");
	   }     
     
     });

  	});

Feel free to do ask comments in the comments box if you face any issue.