Below, you’ll find a detailed guide on how to add the Easy PayPal & Stripe Buy Now Button Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Easy PayPal & Stripe Buy Now Button Plugin shortcode not to show or not to work correctly.
Before starting, here is an overview of the Easy PayPal & Stripe Buy Now Button Plugin and the shortcodes it provides:
"Easy PayPal & Stripe Buy Now Button is a robust WordPress plugin. Simplify your ecommerce process by integrating PayPal and Stripe payment methods directly into your site with just a click."
- [wpecpp]
Easy PayPal & Stripe Buy Now Button [wpecpp] Shortcode
The ‘wpecpp’ shortcode is designed to facilitate e-commerce transactions in WordPress. It generates a form for PayPal and Stripe payments, aligns it according to user preference, and displays a success or error message post-transaction.
Shortcode: [wpecpp]
Parameters
Here is a list of all possible wpecpp shortcode parameters and attributes:
name
– Specifies the name of the product or service.price
– Sets the price of the product or service.size
– Defines the size of the product or service.align
– Aligns the payment form either to the ‘left’, ‘right’, or ‘center’.
Examples and Usage
Basic example – Display a product with the name ‘T-Shirt’, a price of ’20’, and the size of ‘M’ aligned to the ‘center’
[wpecpp name="T-Shirt" price="20" size="M" align="center"]
Advanced examples
Display a product with the name ‘Winter Jacket’, a price of ‘100’, and the size of ‘L’ aligned to the ‘left’
[wpecpp name="Winter Jacket" price="100" size="L" align="left"]
Display a product with the name ‘Summer Dress’, a price of ’50’, and the size of ‘S’ aligned to the ‘right’
[wpecpp name="Summer Dress" price="50" size="S" align="right"]
It’s important to note that the ‘name’ and ‘price’ attributes are mandatory for the shortcode to work properly. The ‘size’ and ‘align’ attributes are optional and will default to ” and ‘left’ respectively if not provided.
PHP Function Code
In case you have difficulties debugging what causing issues with [wpecpp]
shortcode, check below the related PHP functions code.
Shortcode line:
add_shortcode( 'wpecpp', 'wpecpp_shortcode' );
Shortcode PHP function:
function wpecpp_shortcode( $atts ) {
// get shortcode values
$atts = shortcode_atts(
[
'name' => '',
'price' => '',
'size' => '',
'align' => ''
],
$atts
);
$atts = array_map( 'esc_attr', $atts );
$rand_string = substr(md5(mt_rand()), 0, 7);
// alignment
switch ( $atts['align'] ) {
case 'left':
$alignment = ' wpecpp-align-left';
break;
case 'right':
$alignment = ' wpecpp-align-right';
break;
case 'center':
$alignment = ' wpecpp-align-center';
break;
default:
$alignment = ' wpecpp-align-left';
}
// paypal account data
$paypal_connection_data = wpecpp_paypal_connection_data( $atts['size'] );
// stripe account data
$stripe_account_data = wpecpp_stripe_account_data();
$output = "<div class='wpecpp-container{$alignment}'>";
if ( empty( $paypal_connection_data ) && empty( $stripe_account_data ) ) {
$output .= __( '(Please enter your Payment methods data on the settings pages.)' );
} else {
if ( !empty( $paypal_connection_data ) && $paypal_connection_data['connection_type'] === 'manual' ) {
$output .= "<form class='wpecpp-form' target='{$paypal_connection_data['target']}' id={$rand_string} action='https://www.{$paypal_connection_data['path']}.com/cgi-bin/webscr' method='post'>";
$output .= "<input type='hidden' name='cmd' value='_xclick' />";
$output .= "<input type='hidden' name='business' value='{$paypal_connection_data['account']}' />";
$output .= "<input type='hidden' name='currency_code' value='{$paypal_connection_data['currency']}' />";
$output .= "<input type='hidden' name='lc' value='{$paypal_connection_data['locale']}'>";
$output .= "<input type='hidden' name='no_note' value=''>";
$output .= "<input type='hidden' name='paymentaction' value='{$paypal_connection_data['paymentaction']}'>";
$output .= "<input type='hidden' name='return' value='{$paypal_connection_data['return']}' />";
$output .= "<input type='hidden' name='bn' value='WPPlugin_SP'>";
$output .= "<input type='hidden' name='cancel_return' value='{$paypal_connection_data['cancel']}' />";
$output .= "<input style='border: none;' class='paypalbuttonimage' type='image' src='{$paypal_connection_data['img']}' border='0' name='submit' alt='Make your payments with PayPal. It is free, secure, effective.' />";
$output .= "<img alt='' border='0' style='border:none;display:none;' src='https://www.paypal.com/{$paypal_connection_data['locale']}/i/scr/pixel.gif' width='1' height='1' />";
} else {
$output .= "<form class='wpecpp-form' action='#' id={$rand_string} method='post'>";
}
if ( !empty( $paypal_connection_data ) && $paypal_connection_data['connection_type'] === 'ppcp' ) {
$output .= wpecpp_ppcp_html( $paypal_connection_data, $rand_string );
}
if ( !empty( $stripe_account_data ) ) {
$message = '';
if ( isset( $_GET['wpecpp_stripe_success'] ) ) {
if ( $_GET['wpecpp_stripe_success'] == 1 ) {
$message = '<span class="payment-success">' . __( 'The payment was successful' ) . '</span>';
} elseif ( $_GET['wpecpp_stripe_success'] == 0 ) {
if ( isset($_GET['payment_cancelled']) && $_GET['payment_cancelled'] == 1 ) {
$message = '<span class="payment-error">' . __( 'The payment was cancelled' ) . '</span>';
} else {
$message = '<span class="payment-error">' . __( 'An unknown payment error has occurred. Please try again' ) . '</span>';
}
}
}
$output .= "<style>.wpecpp-stripe-button-container > * {max-width: {$stripe_account_data['width']}px;}</style>";
$output .= "<div class='wpecpp-stripe-button-container'>";
$output .= "<a href='#' class='wpecpp-stripe-button'><span>" . __( 'Pay with Stripe' ) . "</span></a>";
$output .= "</div>";
$output .= "<div class='wpecpp-payment-message'>{$message}</div>";
}
$output .= "<input type='hidden' name='item_name' value='{$atts['name']}' />";
$output .= "<input type='hidden' name='amount' value='{$atts['price']}' />";
$output .= "</form>";
}
$output .= '</div>';
return $output;
}
Code file location:
wp-ecommerce-paypal/wp-ecommerce-paypal/includes/public_shortcode.php
Conclusion
Now that you’ve learned how to embed the Easy PayPal & Stripe Buy Now Button Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.
Leave a Reply