Open Source Code

WordPress PayPal Shortcode

Overview

Author
FWD:labs

Requirements
WordPress 4.9+, PayPal.com Account

Version (Last Updated)
1.00 (2017-11-17 09:10:11)

License

The MIT License (MIT)

Copyright (c) 2016 FWD:labs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Instructions

1. Add this code to your WordPress theme's functions.php file.
2. Use shortcode [paypal value="XXXXXXXXXX"] -- after replacing PayPal's unique "hosted button ID" for the X's -- in a post on WordPress and see the full PayPal form code on the published page.
3. Test your own button to ensure your hosted button ID is routing to your PayPal item.

Code

function get_paypal($atts) {

	// default parameters
	extract(shortcode_atts( array('value' => ''), $atts)); 

	if ($value) {
	
		$get_paypal = <<<EOD
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="'.$value.'"><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>
EOD;
		
		return $get_paypal;
	
	} else {
	
		return null;
	
	}
  
}

add_shortcode('paypal','get_paypal');

Changelog

Feedback

Questions, comments, concerns or ideas about this? Please let us know.

Twitter   Facebook   Instagram