Easy PayPal & Stripe Buy Now Button Shortcode

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:

Plugin Icon
Easy PayPal & Stripe Buy Now Button

"Easy PayPal & Stripe Buy Now Button is a convenient plugin that simplifies the addition of PayPal and Stripe payment options to your WP eCommerce website, enhancing online shopping experiences."

★★★★✩ (23) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: 5.4
Included Shortcodes:
  • [wpecpp]

Easy PayPal & Stripe Buy Now Button [wpecpp] Shortcode

The WP eCommerce PayPal plugin shortcode is a powerful tool that facilitates online transactions. This shortcode enables users to customize their eCommerce site with specific attributes like the name, price, size, and alignment of a product. It generates a unique form for each transaction, ensuring secure payment processing with PayPal or Stripe. The shortcode also allows for payment status feedback, enhancing the user experience.

Shortcode: [wpecpp]

Parameters

Here is a list of all possible wpecpp shortcode parameters and attributes:

  • name – Defines the name of the product or service
  • price – Sets the price for the product or service
  • size – Determines the size of the payment button
  • align – Sets the alignment of the payment button (left, right, center)

Examples and Usage

Basic example – A simple usage of the shortcode to add a product with a specific name and price.

[wpecpp name="Product Name" price="99.99" /]

Advanced examples

Using the shortcode to add a product with a specified name, price, size, and alignment. The product will be displayed with the specified alignment on the page.

[wpecpp name="Product Name" price="99.99" size="large" align="center" /]

Using the shortcode to add a product with a specified name, price, and alignment. The product will be aligned to the right side of the page.

[wpecpp name="Product Name" price="99.99" align="right" /]

Using the shortcode to add a product with a specified name, price, and size. The size attribute can be used to specify the size of the product button.

[wpecpp name="Product Name" price="99.99" size="small" /]

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *