Afterpay Gateway for WooCommerce Shortcodes

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

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

Plugin Icon
Afterpay Gateway for WooCommerce

"Afterpay Gateway for WooCommerce is a powerful plugin that allows your customers to pay for their purchases over time, enhancing user experience and boosting sales on your WooCommerce store."

★★★☆✩ (43) Active Installs: 20000+ Tested with: 6.3.2 PHP Version: false
Included Shortcodes:
  • [afterpay_product_logo]
  • [afterpay_paragraph]

Afterpay Gateway for WooCommerce [afterpay_product_logo] Shortcode

The Afterpay Gateway for WooCommerce plugin shortcode allows you to display the Afterpay logo on your product page. The shortcode is customizable, letting you choose the logo theme. This shortcode fetches the logo from Afterpay’s static URL, then generates the image source sets. The logo’s appearance can be adjusted by changing the ‘theme’ attribute. The default theme is ‘colour’, but ‘black’ and ‘white’ are also available.

Shortcode: [afterpay_product_logo]

Parameters

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

  • theme – sets the color scheme of the Afterpay logo, can be ‘colour’, ‘black’, or ‘white’

Examples and Usage

Basic example – The shortcode displays the Afterpay logo with the default color theme.

[afterpay_product_logo /]

Advanced examples

Using the shortcode to display the Afterpay logo with a specific color theme. The shortcode accepts ‘colour’, ‘black’, and ‘white’ as valid theme parameters. If an invalid theme is passed, it will default to ‘colour’.

[afterpay_product_logo theme="black" /]

Here is another example with the ‘white’ theme:

[afterpay_product_logo theme="white" /]

Note: The shortcode is case sensitive. Make sure to use lowercase for the theme parameter to avoid any issues.

PHP Function Code

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

Shortcode line:

add_shortcode( 'afterpay_product_logo', array($this, 'shortcode_afterpay_product_logo') );

Shortcode PHP function:

function shortcode_afterpay_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_Afterpay::getInstance();
			$static_url = $gateway_instance->get_static_url();
			$image_path = "integration/product-page/logo-afterpay-{$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="100"
				height="21"
				alt="Afterpay" /><?php

			return ob_get_clean();
		}

Code file location:

afterpay-gateway-for-woocommerce/afterpay-gateway-for-woocommerce/afterpay-gateway-for-woocommerce.php

Afterpay Gateway for WooCommerce [afterpay_paragraph] Shortcode

The Afterpay Gateway for WooCommerce shortcode allows you to display specific product details on your website. Shortcode Name: afterpay_paragraph. This shortcode fetches product data based on the provided ‘id’. If no ‘id’ is given, it retrieves the data from the current post. .

Shortcode: [afterpay_paragraph]

Parameters

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

  • type – determines the type of content to be displayed, default is ‘product’
  • id – specifies the unique identifier of the product

Examples and Usage

Basic example – The following shortcode displays Afterpay information for a specific product by using the product’s id.

[afterpay_paragraph id=123 /]

Advanced examples

Using the shortcode to display Afterpay information for a product by referencing the product type and id. If the product is not found by id, it will try to get the product from the post.

[afterpay_paragraph type="product" id=456 /]

Using the shortcode to display Afterpay information for a product by only referencing the product type. In this case, it will try to get the product from the post.

[afterpay_paragraph type="product" /]

Using the shortcode without any parameters. In this case, it will try to get the product from the post.

[afterpay_paragraph /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'afterpay_paragraph', array($gateway, 'shortcode_afterpay_paragraph') );

Shortcode PHP function:

function shortcode_afterpay_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:

afterpay-gateway-for-woocommerce/afterpay-gateway-for-woocommerce/afterpay-gateway-for-woocommerce.php

Conclusion

Now that you’ve learned how to embed the Afterpay 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 *