490 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

I have a form which has a custom url set by a previous page …

The url for the form looks like:

paypal-payment-page/?package=Graduate bronze £65

Is there a way I can extract the price from the url and then add it into a PHP variable?

1452 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

Sure, try something like this:

$price = isset( $_GET['package'] ) ? intval( strtok( $_GET['package'], '£' ) ) : 0;

If “package” parameter is set, $price will become variable of type int of the numbers after “£”, else it becomes 0.

490 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

Only displays 0 on any of the packages.

The package isn’t sent as a form, basically it’s a custom URL

The code I use to set the URL is:

<a href="<?php echo home_url(); ?>/paypal-payment-page?package=<?php the_title(); ?> bronze £<?php echo get_post_meta($post->ID, '_cmb_bronze_package_price', true); ?>">Buy Now</a>

The code above pre-fills an input in a web form, which works fine, I just need to extract the price to set up a paypal button.

1452 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says

On the form page, please do

var_dump( $_GET );

and tell me the output.
79 posts
  • Kosovo
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Has been a member for 3-4 years
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
vuzzu says

Or just do a simple explode:

$the_price = explode( '£', $_URL_VAR ); 
$the_price = $the_price[1]; // Get the numbers at the end of that url.

However setting a price on url is not that recommended, you must do these things on server side.

490 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says

On the form page, please do
var_dump( $_GET );
and tell me the output.

I get the following:

 array(1) { ["package"]=> string(20) "Graduate bronze £65" } 
104 posts
  • Most Wanted Bounty Winner
  • Exclusive Author
  • Greece
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Bought between 1 and 9 items
  • Sold between 10 000 and 50 000 dollars
Maxdp says

Or just do a simple explode:
$the_price = explode( '£', $_URL_VAR ); 
$the_price = $the_price[1]; // Get the numbers at the end of that url.
However setting a price on url is not that recommended, you must do these things on server side.

^ this

1452 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says


On the form page, please do
var_dump( $_GET );
and tell me the output.

I get the following:

 array(1) { ["package"]=> string(20) "Graduate bronze £65" } 
Can you please paste the output of this then:
var_dump( isset( $_GET['package'] ) );
var_dump( strtok( $_GET['package'], '£' ) );
var_dump( strtok( '£' ) );
490 posts
  • Bought between 10 and 49 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • United Kingdom
Gareth_Gillman says



On the form page, please do
var_dump( $_GET );
and tell me the output.

I get the following:

 array(1) { ["package"]=> string(20) "Graduate bronze £65" } 
Can you please paste the output of this then:
var_dump( isset( $_GET['package'] ) );
var_dump( strtok( $_GET['package'], '£' ) );
var_dump( strtok( '£' ) );
 bool(true) string(16) "Graduate silver " string(2) "75" 
1452 posts
  • Has been a member for 2-3 years
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
  • Croatia
OriginalEXE says




On the form page, please do
var_dump( $_GET );
and tell me the output.

I get the following:

 array(1) { ["package"]=> string(20) "Graduate bronze £65" } 
Can you please paste the output of this then:
var_dump( isset( $_GET['package'] ) );
var_dump( strtok( $_GET['package'], '£' ) );
var_dump( strtok( '£' ) );
 bool(true) string(16) "Graduate silver " string(2) "75" 

Ok, then this should work:

$price = isset( $_GET['package'] ) ? intval( strtok( $_GET['package'], '£' ) ) : 0;
$price = intval( strtok( '£' ) );
by
by
by
by
by
by