Payment Gateway for PayPal on WooCommerce Shortcode

Below, you’ll find a detailed guide on how to add the Payment Gateway for PayPal on WooCommerce 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 Payment Gateway for PayPal on WooCommerce Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Payment Gateway for PayPal on WooCommerce Plugin and the shortcodes it provides:

Plugin Icon
Payment Gateway for PayPal on WooCommerce

"Payment Gateway for PayPal on WooCommerce is a user-friendly plugin that seamlessly integrates PayPal payments into your WooCommerce store, facilitating secure and swift transactions."

★★★★✩ (33) Active Installs: 5000+ Tested with: 6.2.3 PHP Version: 7.0
Included Shortcodes:
  • [ppcp_bnpl_message]

Payment Gateway for PayPal on WooCommerce [ppcp_bnpl_message] Shortcode

The Woo-PayPal-Gateway plugin shortcode, ‘ppcp_bnpl_message’, enables ‘Pay Later’ messaging on specific pages. It checks if ‘Pay Later’ is enabled for the page and validates the ‘placement’ attribute. The shortcode also sets default attributes if not provided, enqueues necessary scripts and styles, and finally, returns a div element to display the ‘Pay Later’ message.

Shortcode: [ppcp_bnpl_message]

Parameters

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

  • placement – Specifies where the message will be displayed (home, category, product, cart, payment).
  • style – Defines the visual style of the message (text, color, ratio).
  • logotype – Determines the type of logo used in the message.
  • logoposition – Sets the position of the logo in the message.
  • textsize – Modifies the size of the text in the message.
  • textcolor – Changes the color of the text in the message.
  • color – Changes the color of the message’s background.
  • ratio – Adjusts the width-height ratio of the message.

Examples and Usage

Basic example – A simple usage of the shortcode to display the PayPal Pay Later message on the home page.

[ppcp_bnpl_message placement="home"]

Advanced examples

Displaying the PayPal Pay Later message on the product page with a text style, a specific logotype, and logoposition.

[ppcp_bnpl_message placement="product" style="text" logotype="primary" logoposition="left"]

Displaying the PayPal Pay Later message on the cart page with a specific style, color, and ratio. This example shows how to use the shortcode when you want to customize the appearance of the message.

[ppcp_bnpl_message placement="cart" style="flex" color="blue" ratio="8x1"]

Displaying the PayPal Pay Later message on the payment page with a specific text size and color. This example shows how to use the shortcode to customize the text size and color of the message.

[ppcp_bnpl_message placement="payment" style="text" textsize="14px" textcolor="#000000"]

PHP Function Code

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

Shortcode line:

add_shortcode('ppcp_bnpl_message', array($this, 'ppcp_bnpl_message_shortcode'), 10);

Shortcode PHP function:

function ppcp_bnpl_message_shortcode($atts) {
        if (empty($atts['placement'])) {
            return '';
        }
        if (!in_array($atts['placement'], array('home', 'category', 'product', 'cart', 'payment'))) {
            return;
        }
        if ($this->is_paypal_pay_later_messaging_enable_for_page($page = $atts['placement']) === false) {
            return false;
        }
        if ($this->is_paypal_pay_later_messaging_enable_for_shoerpage($page = $atts['placement']) === false) {
            return false;
        }
        $placement = $atts['placement'];
        if (!isset($atts['style'])) {
            $atts['style'] = $this->ppcp_pay_later_messaging_get_default_value('style', $placement);
        }
        if ($atts['style'] === 'text') {
            $default_array = array(
                'placement' => 'home',
                'style' => $atts['style'],
                'logotype' => $this->ppcp_pay_later_messaging_get_default_value('logotype', $placement),
                'logoposition' => $this->ppcp_pay_later_messaging_get_default_value('logoposition', $placement),
                'textsize' => $this->ppcp_pay_later_messaging_get_default_value('textsize', $placement),
                'textcolor' => $this->ppcp_pay_later_messaging_get_default_value('textcolor', $placement),
            );
        } else {
            $default_array = array(
                'placement' => 'home',
                'style' => $atts['style'],
                'color' => $this->ppcp_pay_later_messaging_get_default_value('color', $placement),
                'ratio' => $this->ppcp_pay_later_messaging_get_default_value('ratio', $placement)
            );
        }
        $atts = array_merge(
                $default_array, (array) $atts
        );
        wp_enqueue_script('ppcp-checkout-js');
        wp_enqueue_style("ppcp-paypal-checkout-for-woocommerce-public");
        wp_enqueue_script('ppcp-pay-later-messaging-shortcode', WPG_PLUGIN_ASSET_URL . 'ppcp/public/js/pay-later-messaging/shortcode.js', array('jquery'), WPG_PLUGIN_VERSION, true);
        $this->ppcp_paypal_pay_later_messaging_js_enqueue($placement_default = 'shortcode', $atts);
        return '<div class="ppcp_message_shortcode"></div>';
    }

Code file location:

woo-paypal-gateway/woo-paypal-gateway/ppcp/includes/class-ppcp-paypal-checkout-for-woocommerce-pay-later-messaging.php

Conclusion

Now that you’ve learned how to embed the Payment Gateway for PayPal on WooCommerce 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 *