Skip to content

Instantly share code, notes, and snippets.

@darrenmeehan
Created August 5, 2012 18:01
Show Gist options
  • Select an option

  • Save darrenmeehan/3266387 to your computer and use it in GitHub Desktop.

Select an option

Save darrenmeehan/3266387 to your computer and use it in GitHub Desktop.
This is a simple WordPress shortcode to add a Paypal button
<?php
/*
Plugin Name: PayPal Shortcode by Darren
Plugin URI: https://gist.github.com/3266387
Description: This is a simple shortcode to add a Paypal button, just use [paypal] as the shortcode.
Version: 0.1
Author:
Author URI:
License:
License URI:
*/
function dm_paypal_function () {
$productid = get_the_title();
$price = get_post_custom_values('item_price');
echo print_wp_cart_button_for_product("$productid", "$price[0]");
}
add_shortcode('paypal', 'dm_paypal_function');
Copy link
Copy Markdown

ghost commented Aug 5, 2012

it can be:

echo print_wp_cart_button_for_product($productid, $price[0]);

or

echo print_wp_cart_button_for_product("{$productid}", "{$price[0]}");

to better.

@darrenmeehan
Copy link
Copy Markdown
Author

Hi, Just wondering what difference the quotes will make with this. Thanks.

Copy link
Copy Markdown

ghost commented Aug 5, 2012

Double quotes are using for VariableStrings. Like: "Hello $MyNameVariable." also they are slower than Single quotes.

Single quotes are using for SimpleStrings. Like: 'Hello YPY'. also they are faster than Double quotes.

And using { and } to variables, just increase code readability and better it. "Hello {$Micro}soft" <--- !

@darrenmeehan
Copy link
Copy Markdown
Author

Thanks for the help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment