Jump to content

Trying to pass variable to PayPal button in Wordpress


simcoweb

Recommended Posts

In a nutshell, I'm using the Fast Secure Contact Form plugin to create an online rental application. The plugin does pass some variables through the URL of which i've tested and echoed the values to show they do pass properly. The variable passed is the property state since the cost per rental application is different from state to state. This variable is then supposed to pass to the PayPal Buy Now button for payment.

 

This is where i'm stuck.

 

I've pasted the form code into the landing page (after they complete the application it redirects to the payment page and passes the state variable which triggers a  PHP shortcode i've created to populate the line that says: The property is located in STATE and the cost for the application is $XXX . Click the PayPal button below to pay).

 

The goal is that after they complete the application form that the state where the property is located determines the amount of the PayPal button. I'm using this switch code:

 

$state = $_GET['state_name'];
switch ($state) {
case "Washington":
$amount = "$30";
break;
case "Utah":
$amount = "$30";
break;
case "Nevada":
$amount = "$50";
break;
default:
$amount = "$30";
}
if(isset($_GET['state_name'])) {
return "<strong>The application fee for " . $state . "is " . $amount . ". Click the button below to pay via PayPal.</strong>";
} else {
return "<strong>There has been an error. Please return to the form and enter the property address to determine the cost for application fee.</strong>";
}

 

Because Wordpress just doesn't dig it if you put PHP code directly into a page or post (won't execute) I'm using a plugin called Shortcode Exec PHP which allows me to create shortcodes for the PHP I want to execute and I simply embed the shortcode.

 

What I was hoping is that I could insert the PayPal form code directly into the page and add a hidden input for the amount to be passed through. Like this, sort of:

 

<input type="hidden" name="amount" value="<?php echo $amount; ?>" />

 

But, that won't work cuz Wordpress won't execute the PHP code. So, i'm a bit stuck. HOW can I pass that variable to the form? OR, should I possibly think about adding the form code to the shortcode as well and that way the PHP is all parsed and dynamically displays the button? If that would work, how would I set the variable for the amount using proper syntax?

 

Thanks in advance for any and all help! ALWAYS appreciated.

Link to comment
Share on other sites

I went ahead and added the form code to the PHP snippet/shortcode to see if that would work. It does create the button just fine. However, it's not populating the amount to be charged with the right amount.

 

This may be because the button form code was originally generated from the client's account WITH a value/amount in it. That amount may be embedded into the button code and my variable won't override it. OR, i'm using the wrong name for my amount variable. The PayPal site is not real helpful, to say the least. Here's what my PHP code that's executing and creating the button looks like now:

 

$state = $_GET['state_name'];
switch ($state) {
case "Washington":
$amount = "$30";
break;
case "Utah":
$amount = "$30";
break;
case "Nevada":
$amount = "$50";
break;
default:
$amount = "$30";
}
if(isset($_GET['state_name'])) {
return "<p><strong>The application fee for " . $state . " is " . $amount . ". Click the button below to pay via PayPal.</strong></p>" . "<p><form action='https://www.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='amount' value='$amount' /> <input type='hidden' name='cmd' value='_s-xclick'> <input type='hidden' name='hosted_button_id' value='ZSJMKB483BBEA'> <input type='image' src='https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'> <img alt='' border='0' src='https://www.paypalobjects.com/en_US/i/scr/pixel.gif' width='1' height='1'> </form></p>";
} else {
return "<strong>There has been an error. Please return to the form and enter the property address to determine the cost for application fee.</strong>";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.