WP Stripe Checkout Shortcodes

Below, you’ll find a detailed guide on how to add the WP Stripe Checkout Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the WP Stripe Checkout Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the WP Stripe Checkout Plugin and the shortcodes it provides:

Plugin Icon
WP Stripe Checkout

"WP Stripe Checkout is a seamless WordPress plugin that enables secure and swift online payment processing. It integrates Stripe's functionality, offering a user-friendly checkout experience."

★★★★✩ (20) Active Installs: 3000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [wp_stripe_checkout]
  • [wp_stripe_checkout_v3]
  • []
  • [wp_stripe_checkout_payment_link]

WP Stripe Checkout [wp_stripe_checkout] Shortcode

The wp_stripe_checkout shortcode is used to create a checkout button for a specific product. It validates the product ID, type, and ensures the success and cancel URLs are set. The shortcode also supports custom payment methods and allows for the customization of the checkout button’s appearance. It also provides the option to use a template for the button’s display. Shortcode: [wp_stripe_checkout]

Shortcode: [wp_stripe_checkout]

Parameters

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

  • id – Unique identifier for the product in the checkout.
  • payment_method_types – Defines the accepted types of payment methods.
  • template – Determines the display template for the checkout button.

Examples and Usage

Basic example – A simple use of the wp_stripe_checkout shortcode to display a checkout button for a specific product. The product is referenced by its ID.

[wp_stripe_checkout id=1 /]

Advanced examples

Here, the wp_stripe_checkout shortcode is used to display a checkout button for a product with a specific payment method. The product is referenced by its ID and the payment method is defined by the ‘payment_method_types’ attribute.

[wp_stripe_checkout id=1 payment_method_types="card" /]

In this example, the wp_stripe_checkout shortcode is used to display a checkout button for a product with a custom template. The product is referenced by its ID and the template is applied using the ‘template’ attribute.

[wp_stripe_checkout id=1 template=1 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_stripe_checkout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_stripe_checkout', 'wp_stripe_checkout_button_handler');

Shortcode PHP function:

                    function wp_stripe_checkout_button_handler($atts) {
    $atts = array_map('sanitize_text_field', $atts);
    if(!isset($atts['id']) || !is_numeric($atts['id'])){
        return wp_stripe_checkout_legacy_checkout_button_handler($atts);
    }
    $post = get_post($atts['id']);
    if(!$post){
        return __('Invalid product ID', 'wp-stripe-checkout');
    }
    if('wpstripeco_product' != $post->post_type){
        return __('Invalid product type', 'wp-stripe-checkout');
    }
    $options = wp_stripe_checkout_get_option();
    $success_url = $options['success_url'];
    if(!isset($success_url) || empty($success_url)){
        return __('You need to provide a success URL page in the settings', 'wp-stripe-checkout');
    }
    $cancel_url = $options['cancel_url'];
    if(!isset($cancel_url) || empty($cancel_url)){
        return __('You need to provide a cancel URL page in the settings', 'wp-stripe-checkout');
    }
    $payment_method_types = '';
    if(isset($atts['payment_method_types']) && !empty($atts['payment_method_types'])){
        $payment_method_types = sanitize_text_field($atts['payment_method_types']);
    }
    $button_code = '<form action="" method="post">';
    $button_code .= wp_nonce_field('wp_stripe_checkout_button', '_wp_stripe_checkout_button_nonce', true, false);
    $button_code .= '<input type="hidden" name="wpsc_product_id" value="'.esc_attr($atts['id']).'" />';
    $price_input_code = '';
    $price_input_code = apply_filters('wp_stripe_checkout_button_price', $price_input_code, $button_code, $atts);
    if(!empty($price_input_code)){
        $button_code .= $price_input_code;
    }
    $quantity_input_code = '';
    $quantity_input_code = apply_filters('wp_stripe_checkout_button_quantity', $quantity_input_code, $button_code, $atts);
    if(!empty($quantity_input_code)){
        $button_code .= $quantity_input_code;
    }
    if(!empty($payment_method_types)){
        $button_code .= '<input type="hidden" name="payment_method_types" value="'.esc_attr($payment_method_types).'" />';
    }
    $button_code .= '<input type="hidden" name="wp_stripe_checkout_button_input" value="1" />';
    $button_image = get_post_meta($atts['id'], '_wpstripeco_product_button_image', true);
    if(!isset($button_image) || empty($button_image)){
        $button_text = get_post_meta($atts['id'], '_wpstripeco_product_button_text', true);
        if(!isset($button_text) || empty($button_text)){
            $button_text = 'Buy Now';
        }
        $button_code .= '<input type="submit" value="'.esc_attr($button_text).'" />';
    } 
    else{
        $button_code .= '<input type="image" src="'.esc_url($button_image).'" alt="Submit" />';    
    }
    $button_code .= '</form>';
    //template
    if(isset($atts['template']) && $atts['template'] == '1'){
        $button_code = wp_stripe_checkout_button_get_display_template1($button_code, $atts);
    }
    return $button_code;
}
                    

Code file location:

wp-stripe-checkout/wp-stripe-checkout/main.php

WP Stripe Checkout [wp_stripe_checkout_v3] Shortcode

The wp_stripe_checkout_v3 shortcode of the WP Stripe Checkout plugin allows for the creation of a customizable “Buy Now” button. This button redirects users to the Stripe checkout when clicked. The shortcode attributes include button text, price ID or SKU, success and cancel URLs, Stripe publishable key, mode, shipping and billing addresses, locale, and class. If any required attribute is missing, an error message is displayed.

Shortcode: [wp_stripe_checkout_v3]

Parameters

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

  • button_text – Customizes the text displayed on the payment button.
  • price – Defines the product’s price ID.
  • sku – Specifies the SKU of the product.
  • success_url – Sets the URL where users are redirected after successful payment.
  • cancel_url – Determines the URL where users are redirected if they cancel the payment.
  • mode – Sets the payment mode either as ‘payment’ or ‘subscription’.
  • billing_address – If set, collects the billing address of the customer.
  • shipping_address – If set, collects the shipping address of the customer.
  • shipping_countries – Defines the countries allowed for shipping.
  • locale – Sets the language for the payment interface.
  • class – Adds additional CSS classes to the payment button.
  • submit_type – Determines the type of the submit button.
  • button_image – Replaces the payment button with a custom image.

Examples and Usage

Basic example – A simple usage of the shortcode to generate a ‘Buy Now’ button with a specific price ID.

[wp_stripe_checkout_v3 price="price_1Hh1SWHg5mPZGvO3qgZUbJ6E" /]

Advanced examples

Using the shortcode to generate a ‘Subscribe’ button with a specific price ID, and custom success and cancel URLs. The button will redirect to the success URL upon successful payment, and to the cancel URL if the payment is cancelled.

[wp_stripe_checkout_v3 price="price_1Hh1SWHg5mPZGvO3qgZUbJ6E" success_url="http://example.com/success" cancel_url="http://example.com/cancel" mode="subscription" /]

Using the shortcode to generate a ‘Buy Now’ button with a specific SKU, custom button text, and a specified locale. This example also demonstrates how to use the ‘class’ attribute to apply a custom CSS class to the button.

[wp_stripe_checkout_v3 sku="sku_GSb1PbUO3z8RvC" button_text="Purchase Item" locale="fr" class="my-custom-button-class" /]

Using the shortcode to generate a ‘Buy Now’ button with a specific price ID, and custom success and cancel URLs. This example also demonstrates how to use the ‘billing_address’ and ‘shipping_address’ attributes to collect billing and shipping information from the customer.

[wp_stripe_checkout_v3 price="price_1Hh1SWHg5mPZGvO3qgZUbJ6E" success_url="http://example.com/success" cancel_url="http://example.com/cancel" billing_address="required" shipping_address="optional" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_stripe_checkout_v3] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_stripe_checkout_v3', 'wp_stripe_checkout_v3_button_handler');

Shortcode PHP function:

                    function wp_stripe_checkout_v3_button_handler($atts) {
    $atts = array_map('sanitize_text_field', $atts);
    $button_text = 'Buy Now';
    if(isset($atts['button_text']) && !empty($atts['button_text'])){
        $button_text = $atts['button_text'];
    }
    $identifier = '';
    if(!isset($atts['price']) || empty($atts['price'])){  //new API
        //check for existing items that may still use sku
        if(!isset($atts['sku']) || empty($atts['sku'])){
            return __('You need to provide a price ID or sku in the shortcode', 'wp-stripe-checkout');
        }
        else{
            $identifier = $atts['sku'];
        }
    }
    else{
        $identifier = $atts['price'];
    }
    $data_arr = array();
    $line_items_arr = array();
    $line_items_arr['price'] = $identifier;
    $options = wp_stripe_checkout_get_option();
    $success_url = $options['success_url'];
    if(isset($atts['success_url']) && !empty($atts['success_url'])){
        $success_url = $atts['success_url'];
    }
    if(!isset($success_url) || empty($success_url)){
        return __('You need to provide a success URL page in the settings', 'wp-stripe-checkout');
    }
    $data_arr['successUrl'] = $success_url;
    $cancel_url = $options['cancel_url'];
    if(isset($atts['cancel_url']) && !empty($atts['cancel_url'])){
        $cancel_url = $atts['cancel_url'];
    }
    if(!isset($cancel_url) || empty($cancel_url)){
        return __('You need to provide a cancel URL page in the settings', 'wp-stripe-checkout');
    }
    $data_arr['cancelUrl'] = $cancel_url;
    $key = $options['stripe_publishable_key'];
    if(WP_STRIPE_CHECKOUT_TESTMODE){
        $key = $options['stripe_test_publishable_key'];
    }
    if(!isset($key) || empty($key)){
        return __('You need to provide your publishable key in the settings', 'wp-stripe-checkout');
    }
    //mode
    $mode = 'payment';
    if(isset($atts['mode']) && 'subscription' == $atts['mode']){
        $mode = 'subscription';
    }
    $data_arr['mode'] = $mode;
    //billingAddressCollection
    $billingAddressCollection = '';
    if(isset($atts['billing_address']) && !empty($atts['billing_address'])){
        //$billingAddressCollection = "billingAddressCollection: '".$atts['billing_address']."',";
        $data_arr['billingAddressCollection'] = $atts['billing_address'];
    }
    //shippingAddressCollection
    $shippingAddressCollection = '';
    if(isset($atts['shipping_address']) && !empty($atts['shipping_address'])){
        $allowed_countries = wp_stripe_checkout_get_shipping_countries_array();       
        if(isset($atts['shipping_countries']) && !empty($atts['shipping_countries'])){
            $allowed_countries_str = $atts['shipping_countries'];
            $allowed_countries_str = str_replace("'", '', $allowed_countries_str);  //backwards compatibility
            $allowed_countries = array_map('trim', explode(',', $allowed_countries_str));
        }
        //$shippingAddressCollection = "shippingAddressCollection: {allowedCountries: [".$allowed_countries."]},";
        $data_arr['shippingAddressCollection'] = array('allowedCountries' => $allowed_countries);
    }
    //locale
    $locale = '';
    if(isset($atts['locale']) && !empty($atts['locale'])){
        $data_arr['locale'] = $atts['locale'];
    }
    //button class
    $class = '';
    if(isset($atts['class']) && !empty($atts['class'])){
        $class = " ".$atts['class'];
    }
    //submit type
    $submit_type = '';
    if(isset($atts['submit_type']) && !empty($atts['submit_type'])){
        $submit_type = apply_filters('wp_stripe_checkout_v3_submit_type', $submit_type, $atts);
        if(!empty($submit_type)){
            $data_arr['submitType'] = $submit_type;
        }
    }
    $id = uniqid();
    $client_reference_id = 'wpsc'.$id;
    $data_arr['clientReferenceId'] = $client_reference_id;
    $qty_input_class_id = 'wpsc'.$id.'_qty_input';
    $atts['qty_input_class_id'] = $qty_input_class_id;
    $line_items_arr['quantity'] = ' Number(btnqty_'.$id.'.value) ';
    $data_arr['lineItems'] = array($line_items_arr);
    $data_arr_json = json_encode($data_arr);
    $data_arr_json = str_replace('" ', '', $data_arr_json);
    $data_arr_json = str_replace(' "', '', $data_arr_json);
    $button_code = '<div class="wpsc-v3-button-container">';
    $quantity_input_code = '';
    $quantity_input_code = apply_filters('wp_stripe_checkout_v3_quantity', $quantity_input_code, $button_code, $atts);
    if(!empty($quantity_input_code)){
        $button_code .= $quantity_input_code;
    }
    else{
        $button_code .= '<input class="wpstripeco_variable_quantity_input '.$qty_input_class_id.'" type="hidden" name="item_quantity" value="1" required>';
    }
    $button = '<button id="wpsc'.$id.'" class="wpsc-v3-button'.$class.'">'.$button_text.'</button>';
    if(isset($atts['button_image']) && !empty($atts['button_image'])){
        $button = '<a href="#" onclick="event.preventDefault();" id="wpsc'.$id.'" class="wpsc-v3-button'.$class.'"><img src="'.$atts['button_image'].'"></a>';
    }
    $button_code .= $button;
    $button_code .= '</div>';
    $button_code .= <<<EOT
    <div id="error-wpsc$id"></div>
    <script>
    (function() {
        var stripe_$id = Stripe('$key');
        var checkoutButton_$id = document.querySelector('#wpsc$id');
        var btnqty_$id = document.querySelector('.{$qty_input_class_id}');
        var data_arr_$id = $data_arr_json;
        btnqty_$id.addEventListener('change', function (e) {    
            var qty = e.target;
            //console.log("type: "+qty.type+", value: "+qty.value);    
            if(isNaN(qty.value)){
                return;
            }
            if(qty.max && qty.value > qty.max){
                qty.value = qty.max;
            }
            if(qty.min && qty.value < qty.min){
                qty.value = qty.min;
            }        
            data_arr_$id = $data_arr_json;
        });
        //console.log(data_arr_$id);
        checkoutButton_$id.addEventListener('click', function () {
            stripe_$id.redirectToCheckout(data_arr_$id)
            .then(function (result) {
                if (result.error) {
                  var displayError = document.getElementById('error-wpsc$id');
                  displayError.textContent = result.error.message;
                }
            })
            .catch(function(error) {
                console.error('Error:', error);
                var displayError = document.getElementById('error-wpsc$id');
                displayError.textContent = error;
            });
        });
    })();
    </script>        
EOT;
    return $button_code;
}
                    

Code file location:

wp-stripe-checkout/wp-stripe-checkout/main.php

WP Stripe Checkout [null] Shortcode

The wp-stripe-checkout plugin shortcode is a powerful tool for integrating Stripe payment gateway into your WordPress site. This shortcode, [wp_stripe_checkout_session], generates a ‘Buy Now’ button that initiates a Stripe checkout session. The shortcode accepts several attributes, allowing customization of the checkout process. These include the item name, description, currency, success URL, cancel URL, and more. It also supports optional parameters for collecting billing addresses, phone numbers, and promotional codes. The shortcode ensures secure transactions by sanitizing input fields and validating key settings, providing error messages if necessary. This makes it a reliable and user-friendly solution for handling Stripe payments on your WordPress site.

Shortcode: [null]

Parameters

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

  • name – The name of the item being sold.
  • description – A brief description of the item.
  • button_text – Custom text for the checkout button.
  • currency – The currency code for the transaction.
  • success_url – URL to redirect after successful payment.
  • cancel_url – URL to redirect if payment is cancelled.
  • billing_address – Collects customer’s billing address.
  • phone_number_collection – Enables collection of customer’s phone number.
  • allow_promotion_codes – Allows usage of promotional codes.
  • submit_type – Defines the submit button type.
  • terms_of_service – Links to the terms of service document.
  • tax_id_collection – Enables collection of customer’s tax ID.
  • consent_collection_promotions – Collects consent for promotional content.
  • payment_method_types – Specifies the payment methods accepted.
  • prefill_wp_email – Prefills the email field with WordPress user email.
  • class – Adds a custom class to the form.
  • price – The price of the item being sold.
  • button_image – URL of the image to be used as the submit button.

Examples and Usage

Basic example – Display a basic Stripe checkout session button with the name of the item.

[wp_stripe_checkout_session name="My Product"]

Advanced examples

Creating a Stripe checkout session button with a custom button text, currency and success URL.

[wp_stripe_checkout_session name="My Product" button_text="Purchase Now" currency="USD" success_url="http://example.com/success"]

Using the shortcode to display a Stripe checkout session button with additional parameters such as billing address, phone number collection, and allow promotion codes.

[wp_stripe_checkout_session name="My Product" billing_address="true" phone_number_collection="true" allow_promotion_codes="true"]

Creating a Stripe checkout session button with a custom button image, and prefill email option.

[wp_stripe_checkout_session name="My Product" button_image="http://example.com/image.jpg" prefill_wp_email="true"]

PHP Function Code

In case you have difficulties debugging what causing issues with [null] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_stripe_checkout_session', 'wp_stripe_checkout_session_button_handler');

Shortcode PHP function:

                    function wp_stripe_checkout_session_button_handler($atts) {
    $atts = array_map('sanitize_text_field', $atts);
    if(!isset($atts['name']) || empty($atts['name'])){
        return __('You need to provide a name for your item', 'wp-stripe-checkout');
    }
    $item_name = $atts['name'];
    $item_description = '';
    if(isset($atts['description']) && !empty($atts['description'])){
        $item_description = $atts['description'];
    }
    $button_text = 'Buy Now';
    if(isset($atts['button_text']) && !empty($atts['button_text'])){
        $button_text = $atts['button_text'];
    }  
    $options = wp_stripe_checkout_get_option();
    $currency = $options['stripe_currency_code'];
    if(isset($atts['currency']) && !empty($atts['currency'])){
        $currency = $atts['currency'];
    }
    $success_url = $options['success_url'];
    if(isset($atts['success_url']) && !empty($atts['success_url'])){
        $success_url = $atts['success_url'];
    }
    //check to make sure that the success_url is set
    if(!isset($success_url) || empty($success_url)){
        return __('You need to provide a return URL page in the settings', 'wp-stripe-checkout');
    }
    $cancel_url = home_url();
    if(isset($atts['cancel_url']) && !empty($atts['cancel_url'])){
        $cancel_url = $atts['cancel_url'];
    }
    $billing_address = '';
    if(isset($atts['billing_address']) && !empty($atts['billing_address'])){
        $billing_address = sanitize_text_field($atts['billing_address']);
    }
    $phone_number_collection = '';
    if(isset($atts['phone_number_collection']) && !empty($atts['phone_number_collection'])){
        $phone_number_collection = sanitize_text_field($atts['phone_number_collection']);
    }
    $allow_promotion_codes = '';
    if(isset($atts['allow_promotion_codes']) && !empty($atts['allow_promotion_codes'])){
        $allow_promotion_codes = sanitize_text_field($atts['allow_promotion_codes']);
    }
    $submit_type = '';
    if(isset($atts['submit_type']) && !empty($atts['submit_type'])){
        $submit_type = sanitize_text_field($atts['submit_type']);
    }
    $terms_of_service = '';
    if(isset($atts['terms_of_service']) && !empty($atts['terms_of_service'])){
        $terms_of_service = sanitize_text_field($atts['terms_of_service']);
    }
    $tax_id_collection = '';
    if(isset($atts['tax_id_collection']) && !empty($atts['tax_id_collection'])){
        $tax_id_collection = sanitize_text_field($atts['tax_id_collection']);
    }
    $consent_collection_promotions = '';
    if(isset($atts['consent_collection_promotions']) && !empty($atts['consent_collection_promotions'])){
        $consent_collection_promotions = sanitize_text_field($atts['consent_collection_promotions']);
    }
    $payment_method_types = '';
    if(isset($atts['payment_method_types']) && !empty($atts['payment_method_types'])){
        $payment_method_types = sanitize_text_field($atts['payment_method_types']);
    }
    $prefill_wp_email = '';
    if(isset($atts['prefill_wp_email']) && !empty($atts['prefill_wp_email'])){
        $prefill_wp_email = sanitize_text_field($atts['prefill_wp_email']);
    }
    $key = $options['stripe_publishable_key'];
    if(WP_STRIPE_CHECKOUT_TESTMODE){
        $key = $options['stripe_test_publishable_key'];
    }
    if(!isset($key) || empty($key)){
        return __('You need to provide your publishable key in the settings', 'wp-stripe-checkout');
    }
    //button class
    $class = 'wpsc-session';
    if(isset($atts['class']) && !empty($atts['class'])){
        $class = $class." ".$atts['class'];
    }
    $id = uniqid();
    $client_reference_id = 'wpsc'.$id;
    $button_code = '<form class="'.esc_attr($class).'" action="" method="post">';
    $button_code .= wp_nonce_field('wp_stripe_checkout_session_nonce', '_wpnonce', true, false);
    $button_code .= '<input type="hidden" name="client_reference_id" value="'.esc_attr($client_reference_id).'" />';
    $button_code .= '<input type="hidden" name="item_name" value="'.esc_attr($item_name).'" />';
    if(!empty($item_description)){
        $button_code .= '<input type="hidden" name="item_description" value="'.esc_attr($item_description).'" />';
    }
    $price_input_code = '';
    $price_input_code = apply_filters('wp_stripe_checkout_session_price', $price_input_code, $button_code, $atts);
    if(!empty($price_input_code)){
        $button_code .= $price_input_code;
    }
    else{
        if(isset($atts['price']) && is_numeric($atts['price']) && $atts['price'] > 0) {
            $button_code .= '<input type="hidden" name="item_price" value="'.esc_attr($atts['price']).'" />';
        }
        else{
            return __('You need to provide a valid price for your item', 'wp-stripe-checkout');
        }
    }
    $quantity_input_code = '';
    $quantity_input_code = apply_filters('wp_stripe_checkout_session_quantity', $quantity_input_code, $button_code, $atts);
    if(!empty($quantity_input_code)){
        $button_code .= $quantity_input_code;
    }
    $button_code .= '<input type="hidden" name="item_currency" value="'.esc_attr($currency).'" />';
    if(!empty($success_url)){
        $button_code .= '<input type="hidden" name="success_url" value="'.esc_url($success_url).'" />';
    }
    if(!empty($cancel_url)){
        $button_code .= '<input type="hidden" name="cancel_url" value="'.esc_url($cancel_url).'" />';
    }
    if(!empty($billing_address)){
        $button_code .= '<input type="hidden" name="billing_address" value="'.esc_attr($billing_address).'" />';
    }
    if(!empty($phone_number_collection)){
        $button_code .= '<input type="hidden" name="phone_number_collection" value="'.esc_attr($phone_number_collection).'" />';
    }
    if(!empty($allow_promotion_codes)){
        $button_code .= '<input type="hidden" name="allow_promotion_codes" value="'.esc_attr($allow_promotion_codes).'" />';
    }
    if(!empty($submit_type)){
        $button_code .= '<input type="hidden" name="submit_type" value="'.esc_attr($submit_type).'" />';
    }
    if(!empty($terms_of_service)){
        $button_code .= '<input type="hidden" name="terms_of_service" value="'.esc_attr($terms_of_service).'" />';
    }
    if(!empty($tax_id_collection)){
        $button_code .= '<input type="hidden" name="tax_id_collection" value="'.esc_attr($tax_id_collection).'" />';
    }
    if(!empty($consent_collection_promotions)){
        $button_code .= '<input type="hidden" name="consent_collection_promotions" value="'.esc_attr($consent_collection_promotions).'" />';
    }
    if(!empty($payment_method_types)){
        $button_code .= '<input type="hidden" name="payment_method_types" value="'.esc_attr($payment_method_types).'" />';
    }
    if(!empty($prefill_wp_email)){
        $button_code .= '<input type="hidden" name="prefill_wp_email" value="'.esc_attr($prefill_wp_email).'" />';
    }
    $button_code .= '<input type="hidden" name="wp_stripe_checkout_session" value="1" />';
    if(isset($atts['button_image']) && !empty($atts['button_image'])){
        $button_code .= '<input type="image" src="'.esc_url($atts['button_image']).'" alt="Submit" />';    
    }
    else{
        $button_code .= '<input type="submit" value="'.esc_attr($button_text).'" />';
    }
    $button_code .= '</form>';
    return $button_code;
}
                    

Code file location:

wp-stripe-checkout/wp-stripe-checkout/main.php

WP Stripe Checkout [wp_stripe_checkout_payment_link] Shortcode

The WP Stripe Checkout shortcode is a versatile tool for creating a payment link. It sanitizes user input and checks for a valid URL. If none is provided, it prompts for one. The shortcode also allows for email prefilling and custom button text or image. If no customizations are made, it defaults to a “Buy Now” button. It returns a form with the payment link and the specified settings.

Shortcode: [wp_stripe_checkout_payment_link]

Parameters

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

  • url – The payment link URL you want to use.
  • prefill_wp_email – If set, the logged-in user’s email will be prefilled.
  • button_text – The text displayed on your payment button.
  • button_image – An optional image URL for the payment button.

Examples and Usage

Basic Example – An instance of the wp_stripe_checkout_payment_link shortcode that includes a URL for the payment link.

[wp_stripe_checkout_payment_link url="https://yourwebsite.com/payment-link"]

Advanced Examples

1. Using the shortcode to prefill the email of logged-in users and customize the button text.

[wp_stripe_checkout_payment_link url="https://yourwebsite.com/payment-link" prefill_wp_email="true" button_text="Proceed to Payment"]

2. Using the shortcode to include a custom button image instead of a plain text button.

[wp_stripe_checkout_payment_link url="https://yourwebsite.com/payment-link" button_image="https://yourwebsite.com/wp-content/uploads/your-button-image.png"]

Note: In the advanced examples above, replace the URLs “https://yourwebsite.com/payment-link” and “https://yourwebsite.com/wp-content/uploads/your-button-image.png” with your actual payment link URL and the URL of the image you want to use for the button respectively.

PHP Function Code

In case you have difficulties debugging what causing issues with [wp_stripe_checkout_payment_link] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('wp_stripe_checkout_payment_link', 'wp_stripe_checkout_payment_link_button_handler');

Shortcode PHP function:

                    function wp_stripe_checkout_payment_link_button_handler($atts) {
    $atts = array_map('sanitize_text_field', $atts);
    if(!isset($atts['url']) || empty($atts['url'])){
        return __('You need to provide a payment link URL in the shortcode', 'wp-stripe-checkout');
    }
    $button_code = '<form action="'.esc_url($atts['url']).'" method="get">';
    $button_code .= '<input type="hidden" name="client_reference_id" value="wpsc_payment_link" />';
    $email_input_code = '';
    $email_input_code = apply_filters('wpsc_payment_link_button_email', $email_input_code, $button_code, $atts);
    if(!empty($email_input_code)){
        $button_code .= $email_input_code;
    }
    else{
        if(isset($atts['prefill_wp_email']) && !empty($atts['prefill_wp_email'])){
            if(is_user_logged_in()){
                $current_user = wp_get_current_user();
                $email_address = $current_user->user_email;
                $button_code .= '<input type="hidden" name="prefilled_email" value="'.esc_attr($email_address).'" />';
            }           
        }
    }
    $button_text = 'Buy Now';
    if(isset($atts['button_text']) && !empty($atts['button_text'])){
        $button_text = $atts['button_text'];
    }
    //
    if(isset($atts['button_image']) && !empty($atts['button_image'])){
        $button_code .= '<input type="image" src="'.esc_url($atts['button_image']).'" alt="Submit" />';    
    }
    else{
        $button_code .= '<input type="submit" value="'.esc_attr($button_text).'" />';
    }
    $button_code .= '</form>';
    return $button_code;
}
                    

Code file location:

wp-stripe-checkout/wp-stripe-checkout/main.php

Conclusion

Now that you’ve learned how to embed the WP Stripe Checkout Plugin shortcodes, 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 *