Web Development & WordPress

How to show Paypal Buy Now, Cart, Donate or Subscribe button in your wordpress website and Redirect to Paypal page after successful Contact form 7 submission

This is the way I added a Paypal button in a wordpress site and Redirect it to the Paypal Payment Page ( by auto clicking the paypal button) while the Contact Form 7 form mail sent/form submission.

At first please install this Payment Button for PayPal

Go to Settings page of this plugins to put your paypal Client ID and Merchat ID here. I have shared screenshot about How you can find out Paypal Client ID and Merchant ID below.

Get Paypal Client ID

Go to this url Paypal Developer Page for Client ID. Please check if your Paypal is in Sandbox or LIve mode ( I am using sandbox mode)

Paypal Merchant ID

From this url you will get Paypal Merchant ID

put the Paypal button shortcode at the end of Contact form 7

Here you can see few shortcodes. You will get all these from Plugins page

[wp_paypal button="buynow" name="My product" amount="1.00"]
[wp_paypal button="cart" name="My product" amount="1.00"]
[wp_paypal button="viewcart"]
[wp_paypal button="donate" name="My product"]
[wp_paypal button="subscribe" name="My product" a3="1.00" p3="1" t3="M" src="1"]

put an ID to this shortcode as i will make the button Hide from front view

Now add this CSS and JQuery code ( to click on the Paypal button with successful submission and mail sent event). Please Replace the Contact Form 7 ID with your Contact Form 7 ID. I shared screenshot where you can get Contact Form 7 ID below

<style>
#paypal{
visibility:hidden;
height:20px;
		}
</style>	



<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
	console.log("test by om");
    if ( event.detail.contactFormId === "YOUR CONTACT FORM 7 ID") { 
  jQuery('#paypal *').click();
	}}, false );		
</script>

Here You can get Contact Form 7 ID

Leave a comment