560 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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?

1473 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
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.

560 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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.

1473 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
OriginalEXE says

On the form page, please do

var_dump( $_GET );

and tell me the output.
83 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in Kosovo
+2 more
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.

560 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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" } 
113 posts
  • Sells items exclusively on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Won a Most Wanted contest
  • Has sold $10,000+ on Envato Market
+3 more
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

1473 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
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( '£' ) );
560 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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" 
1473 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
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