Clearpay Gateway for WooCommerce Shortcodes

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

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

Plugin Icon
Clearpay Gateway for WooCommerce

"Clearpay Gateway for WooCommerce is a powerful plugin that integrates Clearpay payment solutions into your WooCommerce store, facilitating smoother transactions."

★★★★✩ (5) Active Installs: 2000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [clearpay_product_logo]
  • [clearpay_paragraph]

Clearpay Gateway for WooCommerce [clearpay_product_logo] Shortcode

The Clearpay Gateway for WooCommerce plugin shortcode is used to display the Clearpay product logo on a site. This shortcode allows customization of the logo’s theme (color, black, or white). It fetches the logo from the static URL, generates source sets for different resolutions, and returns an image tag with the logo.

Shortcode: [clearpay_product_logo]

Parameters

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

  • theme – controls the color scheme of the Clearpay logo (‘colour’, ‘black’, ‘white’)

Examples and Usage

Basic example – Displaying the Clearpay logo with the default color theme.

[clearpay_product_logo]

Advanced examples – Displaying the Clearpay logo with different color themes.

Displaying the Clearpay logo with the black theme.

[clearpay_product_logo theme="black"]

Displaying the Clearpay logo with the white theme.

[clearpay_product_logo theme="white"]

Note: If an invalid theme is passed, the default color theme will be used.

[clearpay_product_logo theme="invalid_theme"]

In the last example, since “invalid_theme” is not a valid theme, the color theme will default to the color theme.

PHP Function Code

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

Shortcode line:

add_shortcode( 'clearpay_product_logo', array($this, 'shortcode_clearpay_product_logo') );

Shortcode PHP function:

function shortcode_clearpay_product_logo($atts) {
			$atts = shortcode_atts( array(
				'theme' => 'colour'
			), $atts );

			if (!in_array($atts['theme'], array('colour', 'black', 'white'))) {
				$atts['theme'] = 'colour';
			}

			$gateway_instance = WC_Gateway_Clearpay::getInstance();
			$static_url = $gateway_instance->get_static_url();
			$image_path = "integration/product-page/logo-clearpay-{$atts['theme']}";
			$logo = $gateway_instance->generate_source_sets($static_url, $image_path, 'png');

			ob_start();

			?><img
				style="vertical-align:middle;"
				src="<?php echo esc_url($logo->x1); ?>"
				srcset="
					<?php echo esc_url($logo->x1); ?> 1x,
					<?php echo esc_url($logo->x2); ?> 2x,
					<?php echo esc_url($logo->x3); ?> 3x"
				width="110"
				height="21"
				alt="Clearpay" /><?php

			return ob_get_clean();
		}

Code file location:

clearpay-gateway-for-woocommerce/clearpay-gateway-for-woocommerce/clearpay-gateway-for-woocommerce.php

Clearpay Gateway for WooCommerce [clearpay_paragraph] Shortcode

The Clearpay Gateway for WooCommerce shortcode is a versatile tool that allows you to display Clearpay information on product pages. It utilizes the ‘id’ attribute to fetch specific product data. If no ‘id’ is provided, it retrieves data from the current post. The shortcode then renders this data on product pages, enhancing user experience by providing relevant Clearpay details.

Shortcode: [clearpay_paragraph]

Parameters

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

  • type – determines if the shortcode will display information for a product
  • id – specific product’s unique identifier in WooCommerce

Examples and Usage

Basic Example – A simple shortcode to display product details based on the product ID.

[clearpay_paragraph type="product" id=123 /]

In this example, the shortcode ‘clearpay_paragraph’ is used with two attributes ‘type’ and ‘id’. The ‘type’ attribute is set to ‘product’, indicating that we want to display a product. The ‘id’ attribute is set to ‘123’, which is the ID of the product we want to display.

Advanced Examples

Using the shortcode to display product details without specifying an ID. In this case, the product details will be fetched from the current post.

[clearpay_paragraph type="product" /]

In this advanced example, the shortcode ‘clearpay_paragraph’ is used with only one attribute ‘type’. The ‘type’ attribute is set to ‘product’, indicating that we want to display a product. Since no ‘id’ attribute is provided, the product details will be fetched from the current post.

Using the shortcode to display product details for multiple products by specifying their IDs.

[clearpay_paragraph type="product" id=123 /]
[clearpay_paragraph type="product" id=124 /]
[clearpay_paragraph type="product" id=125 /]

In this advanced example, the shortcode ‘clearpay_paragraph’ is used multiple times to display details for different products. The ‘id’ attribute is used to specify the ID of each product.

PHP Function Code

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

Shortcode line:

add_shortcode( 'clearpay_paragraph', array($gateway, 'shortcode_clearpay_paragraph') );

Shortcode PHP function:

function shortcode_clearpay_paragraph($atts) {
			$atts = shortcode_atts( array(
				'type' => 'product',
				'id'   => 0
			), $atts );

			if(array_key_exists('id',$atts) &&  $atts['id']!=0){
				$product = wc_get_product( $atts['id'] );
			}
			else{
				$product = $this->get_product_from_the_post();
			}

			ob_start();
			if($atts['type'] == "product" && $product instanceof WC_Product){
				$this->render_placement('product-pages', $product);
			}
			return ob_get_clean();
		}

Code file location:

clearpay-gateway-for-woocommerce/clearpay-gateway-for-woocommerce/clearpay-gateway-for-woocommerce.php

Conclusion

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