Accept Stripe Payments Shortcodes

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

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

Plugin Icon
Accept Stripe Payments

"Accept Stripe Payments is a powerful WordPress plugin that enables seamless transactions on your site. With this plugin, you can effortlessly accept payments through Stripe, ensuring a secure and smooth checkout process for your customers."

★★★★✩ (95) Active Installs: 30000+ Tested with: 6.3.2 PHP Version: 7.0
Included Shortcodes:
  • [asp_product_ng]
  • [accept_stripe_payment_ng]
  • [asp_show_all_products]
  • [accept_stripe_payment_checkout]
  • [accept_stripe_payment_checkout_error]
  • [asp_show_my_transactions]
  • [asp_available_quantity]

Accept Stripe Payments [asp_product_ng] Shortcode

The Stripe Payments shortcode is designed to handle product payments on your website. It verifies the product ID, checks for any errors, and retrieves product details such as currency and button text. It also handles product thumbnails, calculates the total price including tax and shipping, and generates the ‘Buy’ button. The shortcode can be customized to collect billing and shipping addresses, and to display the product information in a fancy style template. Shortcode: [asp_product_ng]

Shortcode: [asp_product_ng]

Parameters

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

  • id – Unique identifier of the product.
  • button_text – Customizes the text on the payment button.
  • class – Adds a custom CSS class to the payment button.
  • thankyou_page_url – Sets a custom thank you page URL after successful payment.
  • tax – Manually sets the tax amount for the product.
  • in_the_loop – Determines if the shortcode is within the loop.
  • compat_mode – Enables compatibility mode for the plugin.
  • button_only – Shows only the payment button without product details.
  • fancy – Hides the fancy style template when set to empty.
  • is_post_tpl – Determines if the shortcode is in the post template.

Examples and Usage

Basic example – Display a product with a specified ID

[asp_product_ng id=123 /]

Advanced examples

Display a product with a specified ID and custom button text

[asp_product_ng id=123 button_text="Buy Now!" /]

Display a product with a specified ID, custom button text, and a custom CSS class for styling

[asp_product_ng id=123 button_text="Buy Now!" class="custom-class" /]

Display a product with a specified ID, custom button text, a custom CSS class for styling, and a custom thank you page URL

[asp_product_ng id=123 button_text="Buy Now!" class="custom-class" thankyou_page_url="https://example.com/thank-you" /]

Display a product with a specified ID, and override the product’s tax rate

[asp_product_ng id=123 tax=15 /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'asp_product_ng', array( $this, 'shortcode_asp_product' ) );

Shortcode PHP function:

function shortcode_asp_product( $atts ) {
		if ( ! isset( $atts['id'] ) || ! is_numeric( $atts['id'] ) ) {
			$msg       = __( 'Error: product ID is invalid.', 'stripe-payments' );
			$error_msg = $this->gen_fatal_error_box( $msg );
			return $error_msg;
		}

		$id   = $atts['id'];
		$item = new ASP_Product_Item( $id );

		$last_error = $item->get_last_error();

		if ( $last_error ) {
			$error_msg = $this->gen_fatal_error_box( $last_error );
			return $error_msg;
		}

		$plan_id = get_post_meta( $id, 'asp_sub_plan_id', true );

		if ( ! empty( $plan_id ) && ! class_exists( 'ASPSUB_main' ) ) {
			//Subs addon not installed or disabled. Show corresponding error message
			$error_msg = $this->gen_fatal_error_box( __( 'This product requires Stripe Payments Subscription addon.' ) );
			return $error_msg;
		}

		if ( ! empty( $plan_id ) && class_exists( 'ASPSUB_main' ) && version_compare( ASPSUB_main::ADDON_VER, '2.0.0t1' ) < 0 ) {
			$error_msg = $this->gen_fatal_error_box( 'Stripe Subscriptions addon version 2.0.0 or newer is required.' );
			return $error_msg;
		}

		$currency = $item->get_currency();

		$button_text = $item->get_button_text();

		//check if we have button_text shortcode parameter. If it's not empty, this should be our button text
		if ( isset( $atts['button_text'] ) && ! empty( $atts['button_text'] ) ) {
			$button_text = esc_attr( $atts['button_text'] );
		}

		$thumb_img = '';
		$thumb_url = get_post_meta( $id, 'asp_product_thumbnail', true );

		if ( $thumb_url ) {
			if ( is_ssl() ) {
				$thumb_url = ASP_Utils::url_to_https( $thumb_url );
			}
			$thumb_img = '<img src="' . $thumb_url . '">';
		}

		$url = get_post_meta( $id, 'asp_product_upload', true );

		if ( ! $url ) {
			$url = '';
		}

		$template_name = 'default'; //this could be made configurable
		$button_color  = 'blue'; //this could be made configurable

		$price    = $item->get_price();
		$shipping = $item->get_shipping();

		//let's apply filter so addons can change price, currency and shipping if needed
		$price_arr = array(
			'price'    => $price,
			'currency' => $currency,
			'shipping' => empty( $shipping ) ? false : $shipping,
		);
		$price_arr = apply_filters( 'asp_ng_modify_price_currency_shipping', $price_arr );
		extract( $price_arr, EXTR_OVERWRITE );

		$buy_btn = '';

		$button_class = $item->get_button_class();

		$class = ! empty( $button_class ) ? $button_class : 'asp_product_buy_btn ' . $button_color;

		$class = isset( $atts['class'] ) ? $atts['class'] : $class;

		$custom_field = get_post_meta( $id, 'asp_product_custom_field', true );
		$cf_enabled   = $this->asp_main->get_setting( 'custom_field_enabled' );

		if ( ( '' === $custom_field ) || '2' === $custom_field ) {
			$custom_field = $cf_enabled;
		} else {
			$custom_field = intval( $custom_field );
		}

		if ( ! $cf_enabled ) {
			$custom_field = $cf_enabled;
		}

		$thankyou_page = empty( $atts['thankyou_page_url'] ) ? get_post_meta( $id, 'asp_product_thankyou_page', true ) : $atts['thankyou_page_url'];

		if ( ! $shipping ) {
			$shipping = 0;
		}

		$tax = isset( $atts['tax'] ) ? $atts['tax'] : $item->get_tax();

		if ( ! $tax || $tax < 0 ) {
			$tax = 0;
		}

		if ( isset( $atts['tax'] ) ) {
			//save tax overidden data to session
			$uniq_id = uniqid( 'asp_button', true );
			$sess    = ASP_Session::get_instance();
			$sess->set_transient_data( 'overriden_data_' . $uniq_id, array( 'tax' => $tax ) );
		}

		$quantity = $item->get_quantity();

		$under_price_line = '';
		$tot_price        = ! empty( $quantity ) ? $price * $quantity : $price;

		if ( 0 !== $tax ) {
			$tax_str = apply_filters( 'asp_customize_text_msg', __( 'Tax', 'stripe-payments' ), 'tax_str' );
			if ( ! empty( $price ) ) {
				$tax_amount       = AcceptStripePayments::get_tax_amount( $tot_price, $tax, AcceptStripePayments::is_zero_cents( $currency ) );
				$tot_price       += $tax_amount;
				$under_price_line = '<span class="asp_price_tax_section">' . AcceptStripePayments::formatted_price( $tax_amount, $currency ) . ' (' . strtolower( $tax_str ) . ')</span>';
			} else {
				$under_price_line = '<span class="asp_price_tax_section">' . $tax . '% ' . lcfirst( $tax_str ) . '</span>';
			}
		}
		if ( 0 !== $shipping ) {
			$ship_str      = apply_filters( 'asp_customize_text_msg', __( 'Shipping', 'stripe-payments' ), 'shipping_str' );
			$tot_price    += $shipping;
			$shipping_line = AcceptStripePayments::formatted_price( $shipping, $currency ) . ' (' . strtolower( $ship_str ) . ')';
			if ( ! empty( $under_price_line ) ) {
				$under_price_line .= '<span class="asp_price_shipping_section"> + ' . $shipping_line . '</span>';
			} else {
				$under_price_line = '<span class="asp_price_shipping_section">' . $shipping_line . '</span>';
			}
		}

		if ( ! empty( $price ) && ! empty( $under_price_line ) ) {
			$under_price_line .= '<div class="asp_price_full_total">' . __( 'Total:', 'stripe-payments' ) . ' <span class="asp_tot_current_price">' . AcceptStripePayments::formatted_price( $tot_price, $currency ) . '</span> <span class="asp_tot_new_price"></span></div>';
		}

		if ( get_post_meta( $id, 'asp_product_no_popup_thumbnail', true ) !== 1 ) {
			$item_logo = ASP_Utils::get_small_product_thumb( $id );
		} else {
			$item_logo = '';
		}

		$compat_mode = isset( $atts['compat_mode'] ) ? 1 : 0;

		$this->compat_mode = ( $compat_mode ) ? true : false;

		$billing_address  = get_post_meta( $id, 'asp_product_collect_billing_addr', true );
		$shipping_address = get_post_meta( $id, 'asp_product_collect_shipping_addr', true );

		if ( ! $billing_address ) {
			$shipping_address = false;
		}

		$currency_variable = $item->is_currency_variable();

		//Let's only output buy button if we're in the loop. Since the_content hook could be called several times (for example, by a plugin like Yoast SEO for its purposes), we should only output the button only when it's actually needed.
		if ( ! isset( $atts['in_the_loop'] ) || '1' === $atts['in_the_loop'] ) {
			$sc_params = array(
				'product_id'        => $id,
				'name'              => $item->get_name(),
				'price'             => $price,
				'currency'          => $currency,
				'currency_variable' => $currency_variable,
				'shipping'          => $shipping,
				'tax'               => $tax,
				'class'             => $class,
				'quantity'          => get_post_meta( $id, 'asp_product_quantity', true ),
				'custom_quantity'   => get_post_meta( $id, 'asp_product_custom_quantity', true ),
				'button_text'       => $button_text,
				'description'       => get_post_meta( $id, 'asp_product_description', true ),
				'thankyou_page_url' => $thankyou_page,
				'item_logo'         => $item_logo,
				'billing_address'   => $billing_address,
				'shipping_address'  => $shipping_address,
				'custom_field'      => $custom_field,
				'compat_mode'       => $compat_mode,
				'button_only'       => isset( $atts['button_only'] ) ? intval( $atts['button_only'] ) : null,
				'btn_uniq_id'       => isset( $uniq_id ) ? $uniq_id : '',
			);
			//this would pass additional shortcode parameters from asp_product shortcode
			$sc_params = array_merge( $atts, $sc_params );
			$buy_btn   = $this->shortcode_accept_stripe_payment( $sc_params );
		}

		if ( ! isset( $sc_params['button_only'] ) ) {
			$button_only = get_post_meta( $id, 'asp_product_button_only', true );
		} else {
			$button_only = $sc_params['button_only'];
		}

		if ( ( isset( $atts['fancy'] ) && empty( $atts['fancy'] ) ) || $button_only ) {
			//Just show the stripe payment button (no fancy template)
			$tpl = '<div class="asp_product_buy_button">' . $buy_btn . '</div>';
			wp_enqueue_style( 'asp-default-style' );
			if ( ! $this->compat_mode ) {
				$this->product_css_inserted = true;
			}
			return $tpl;
		}

		//Show the stripe payment button with fancy style template.
		require_once WP_ASP_PLUGIN_PATH . 'public/views/templates/' . $template_name . '/template.php';
		if ( isset( $atts['is_post_tpl'] ) ) {
			$tpl = asp_get_post_template( $this->product_css_inserted );
		} else {
			$tpl = asp_get_template( $this->product_css_inserted );
		}
		if ( ! $this->compat_mode ) {
			$this->product_css_inserted = true;
		}

		$price_line = empty( $price ) ? '' : AcceptStripePayments::formatted_price( $price, $currency );

		$qnt_str = '';
		if ( $quantity && 1 > $quantity ) {
			$qnt_str = 'x ' . $quantity;
		}

		remove_filter( 'the_content', array( $this, 'filter_post_type_content' ) );
		$post = get_post( $id );
		setup_postdata( $post );
		$GLOBALS['post'] = $post;
		$descr           = $post->post_content;
		global $wp_embed;
		if ( isset( $wp_embed ) && is_object( $wp_embed ) ) {
			if ( method_exists( $wp_embed, 'autoembed' ) ) {
				$descr = $wp_embed->autoembed( $descr );
			}
			if ( method_exists( $wp_embed, 'run_shortcode' ) ) {
				$descr = $wp_embed->run_shortcode( $descr );
			}
		}
		$descr = wpautop( do_shortcode( $descr ) );
		wp_reset_postdata();
		add_filter( 'the_content', array( $this, 'filter_post_type_content' ) );

		$product_tags = array(
			'thumb_img'        => $thumb_img,
			'quantity'         => esc_attr( $qnt_str ),
			'name'             => $post->post_title,
			'description'      => $descr,
			'price'            => esc_attr( $price_line ),
			'under_price_line' => wp_kses( $under_price_line, ASP_Utils::asp_allowed_tags() ),
			'buy_btn'          => $buy_btn,
		);

		$product_tags = apply_filters( 'asp_product_tpl_tags_arr', $product_tags, $id );

		foreach ( $product_tags as $tag => $repl ) {
			$tpl = str_replace( '%_' . $tag . '_%', $repl, $tpl );
		}

		return $tpl;
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-asp-shortcode-ng.php

Accept Stripe Payments [accept_stripe_payment_ng] Shortcode

The ‘accept_stripe_payment_ng’ shortcode is designed to dynamically create a Stripe payment button on your WordPress site. This shortcode allows you to specify various parameters like product name, price, quantity, tax, shipping costs, and more.

Shortcode: [accept_stripe_payment_ng]

Parameters

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

  • product_id – Specifies the unique identifier of the product
  • name – Defines the name of the product
  • class – Sets the CSS class for the Stripe button
  • price – Indicates the price of the product
  • shipping – Represents the shipping cost of the product
  • tax – Provides the tax rate for the product
  • quantity – Specifies the number of products to purchase
  • custom_quantity – Allows customization of the product quantity
  • description – Describes the product
  • url – Sets the URL for the product
  • thankyou_page_url – Specifies the URL of the thank you page
  • item_logo – Sets the logo of the product
  • billing_address – Provides the billing address for the purchase
  • shipping_address – Specifies the shipping address for the product
  • customer_email – Sets the customer’s email address
  • customer_name – Provides the name of the customer
  • currency – Defines the currency for the purchase
  • currency_variable – Allows the currency to be variable
  • checkout_lang – Sets the language for the checkout
  • button_text – Defines the text on the payment button
  • compat_mode – Enables or disables compatibility mode

Examples and Usage

Basic Example – Display a product with a defined name, price, and currency.

[accept_stripe_payment_ng name="Test Product" price="25" currency="USD"]

Advanced Examples

Display a product with a defined name, price, currency, custom quantity, and a thank you page URL. The product will have a custom quantity and after the transaction, the user will be redirected to a custom thank you page.

[accept_stripe_payment_ng name="Test Product" price="25" currency="USD" custom_quantity="true" thankyou_page_url="http://www.yourwebsite.com/thank-you"]

Display a product with a defined name, price, currency, and a custom button text. The product will display a custom text on the payment button.

[accept_stripe_payment_ng name="Test Product" price="25" currency="USD" button_text="Buy Now!"]

Display a product with a defined name, price, currency, and a custom description. The product will display a custom description during the transaction.

[accept_stripe_payment_ng name="Test Product" price="25" currency="USD" description="This is a test product"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'accept_stripe_payment_ng', array( $this, 'shortcode_accept_stripe_payment' ) );

Shortcode PHP function:

function shortcode_accept_stripe_payment( $atts ) {
                //Note: It will create a product dynamically using the (ASPMain::$temp_prod_slug) custom post type.
            
		extract(
			shortcode_atts(
				array(
					'product_id'        => 0,
					'name'              => '',
					'class'             => 'stripe-button-el', //default Stripe button class
					'price'             => '0',
					'shipping'          => 0,
					'tax'               => 0,
					'quantity'          => '',
					'custom_quantity'   => false,
					'description'       => '',
					'url'               => '',
					'thankyou_page_url' => '',
					'item_logo'         => '',
					'billing_address'   => '',
					'shipping_address'  => '',
					'customer_email'    => '',
					'customer_name'     => '',
					'currency'          => $this->asp_main->get_setting( 'currency_code' ),
					'currency_variable' => false,
					'checkout_lang'     => $this->asp_main->get_setting( 'checkout_lang' ),
					'button_text'       => $this->asp_main->get_setting( 'button_text' ),
					'compat_mode'       => 0,
				),
				$atts
			)
		);

		$this->compat_mode = ( $compat_mode ) ? true : false;

		if ( empty( $name ) ) {
			$error_msg  = '<div class="stripe_payments_error_msg" style="color: red;">';
			$error_msg .= 'There is an error in your Stripe Payments shortcode. It is missing the "name" field. ';
			$error_msg .= 'You must specify an item name value using the "name" parameter. This value should be unique so this item can be identified uniquely on the page.';
			$error_msg .= '</div>';
			return $error_msg;
		}

		if ( ! empty( $url ) ) {
			$url = base64_encode( $url );
		} else {
			$url = '';
		}

		if ( ! empty( $thankyou_page_url ) ) {
			$thankyou_page_url = base64_encode( $thankyou_page_url );
		} else {
			$thankyou_page_url = '';
		}

		if ( ! is_numeric( $quantity ) ) {
			$quantity = absint( $quantity );
		}

		if ( empty( $quantity ) && '1' !== $custom_quantity ) {
			$quantity = 1;
		}

		$price                   = floatval( $price );
		$uniq_id                 = count( self::$payment_buttons ) . uniqid();
		$button_id               = 'asp_ng_button_' . $uniq_id;
		self::$payment_buttons[] = $button_id;

		$item_price     = $price;
		$payment_amount = $custom_quantity ? $price : floatval( $price ) * $quantity;
		if ( AcceptStripePayments::is_zero_cents( $currency ) ) {
			//this is zero-cents currency, amount shouldn't be multiplied by 100
			$price_in_cents = $payment_amount;
		} else {
			$price_in_cents = $payment_amount * 100;
			$item_price     = $price * 100;
		}

		if ( ! empty( $shipping ) ) {
			$shipping_filt = round( $shipping, 2 );
			if ( ! AcceptStripePayments::is_zero_cents( $currency ) ) {
				$shipping = $shipping_filt * 100;
			} else {
				$shipping = $shipping_filt;
			}
		}

		if ( ! empty( $price ) ) {
			//let's apply tax if needed
			if ( ! empty( $tax ) ) {
				$tax_amount     = round( ( $price_in_cents * $tax / 100 ) );
				$price_in_cents = $price_in_cents + $tax_amount;
			}

			//let's apply shipping cost if needed
			if ( ! empty( $shipping ) ) {
				$price_in_cents = $price_in_cents + $shipping;
			}
		}

		if ( empty( $product_id ) ) {
			$hash = md5( wp_json_encode( $atts ) ) . '5';
			//find temp product
			$temp_post = get_posts(
				array(
					'meta_key'       => 'asp_shortcode_hash',
					'meta_value'     => $hash,
					'posts_per_page' => 1,
					'offset'         => 0,
					'post_type'      => ASPMain::$temp_prod_slug,
				)
			);
			wp_reset_postdata();
			if ( empty( $temp_post ) ) {
				// no temp post found. Let's create one
				$new_post                = array();
				$new_post['post_type']   = ASPMain::$temp_prod_slug;
				$new_post['post_title']  = $atts['name'];
				$new_post['post_status'] = 'publish';
				$new_post['meta_input']  = array(
					'asp_shortcode_hash'                   => $hash,
					'asp_product_quantity'                 => $quantity,
					'asp_product_custom_quantity'          => $custom_quantity,
					'asp_product_price'                    => $price,
					'asp_product_tax'                      => $tax,
					'asp_product_shipping'                 => $shipping,
					'asp_product_currency_variable'        => $currency_variable,
					'asp_product_currency'                 => $currency,
					'asp_product_description'              => $description,
					'asp_product_button_text'              => $button_text,
					'asp_product_collect_billing_addr'     => $billing_address,
					'asp_product_collect_shipping_addr'    => $shipping_address,
					'asp_product_button_class'             => $class,
					'asp_product_upload'                   => base64_decode( $url ),
					'asp_product_thumbnail'                => $item_logo,
					'asp_product_thankyou_page'            => empty( $thankyou_page_url ) ? '' : base64_decode( $thankyou_page_url ),
					'asp_product_button_only'              => 1,
					'asp_product_custom_field'             => 2,
					'asp_product_customer_email_hardcoded' => $customer_email,
					'asp_product_customer_name_hardcoded'  => $customer_name,
				);
				$post_id                 = wp_insert_post( $new_post );
				$temp_post               = get_post( $post_id );
			} else {
				$temp_post = $temp_post[0];
			}
			$atts['id'] = $temp_post->ID;
			$ret        = $this->shortcode_asp_product( $atts );
			return $ret;
		}

		$button_key = md5( htmlspecialchars_decode( $name ) . $price_in_cents );

		//Charge description
		//We only generate it if it's empty and if custom qunatity and price is not used
		//If custom quantity and\or price are used, description will be generated by javascript
		$descr_generated = false;
		if ( empty( $description ) && '1' !== $custom_quantity && ( ! empty( $price ) && 0 !== $price ) ) {
			//Create a description using quantity, payment amount and currency
			if ( ! empty( $tax ) || ! empty( $shipping ) ) {
				$formatted_amount = AcceptStripePayments::formatted_price( AcceptStripePayments::is_zero_cents( $currency ) ? $price_in_cents : $price_in_cents / 100, $currency );
			} else {
				$formatted_amount = AcceptStripePayments::formatted_price( $payment_amount, $currency );
			}
			$description     = "{$quantity} X " . $formatted_amount;
			$descr_generated = true;
		}

		// Check if "Disable Buttons Before Javascript Loads" option is set
		$is_disabled = '';
		if ( $this->asp_main->get_setting( 'disable_buttons_before_js_loads' ) ) {
			$is_disabled = ' disabled';
		}

		$button = sprintf( '<div class="asp_product_buy_btn_container"><button id="%s" type="submit" class="%s"%s><span>%s</span></button></div>', esc_attr( $button_id ), esc_attr( $class ), $is_disabled, sanitize_text_field( $button_text ) );

		$out_of_stock          = false;
		$stock_control_enabled = false;
		$stock_items           = 0;
		//check if stock enabled
		if ( isset( $product_id ) && get_post_meta( $product_id, 'asp_product_enable_stock', true ) ) {
			//check if product is not out of stock
			$stock_items = get_post_meta( $product_id, 'asp_product_stock_items', true );
			if ( empty( $stock_items ) ) {
				$button       = '<div class="asp_out_of_stock">' . __( 'Out of stock', 'stripe-payments' ) . '</div>';
				$out_of_stock = true;
			} else {
				$stock_control_enabled = true;
				$stock_items           = $stock_items;
			}
		}

		//add message if no javascript is enabled
		$button .= '<noscript>' . __( 'Stripe Payments requires Javascript to be supported by the browser in order to operate.', 'stripe-payments' ) . '</noscript>';

		$checkout_lang = empty( $checkout_lang ) ? $this->asp_main->get_setting( 'checkout_lang' ) : $checkout_lang;

		//Currency Display settings
		$display_settings      = array();
		$display_settings['c'] = $this->asp_main->get_setting( 'price_decimals_num', 2 );
		$display_settings['d'] = $this->asp_main->get_setting( 'price_decimal_sep' );
		$display_settings['t'] = $this->asp_main->get_setting( 'price_thousand_sep' );

		$currencies = AcceptStripePayments::get_currencies();
		if ( isset( $currencies[ $currency ] ) ) {
			$curr_sym = $currencies[ $currency ][1];
		} else {
			//no currency code found, let's just use currency code instead of symbol
			$curr_sym = $currencies;
		}

		$curr_pos = $this->asp_main->get_setting( 'price_currency_pos' );

		$display_settings['s']   = $curr_sym;
		$display_settings['pos'] = $curr_pos;

		$display_str = array();
		$tax_str     = apply_filters( 'asp_customize_text_msg', __( 'Tax', 'stripe-payments' ), 'tax_str' );
		$ship_str    = apply_filters( 'asp_customize_text_msg', __( 'Shipping', 'stripe-payments' ), 'shipping_str' );

		$display_str['tax']  = '%s (' . strtolower( $tax_str ) . ')';
		$display_str['ship'] = '%s (' . strtolower( $ship_str ) . ')';

		$base_url = ASP_Utils::get_base_pp_url();

		$url_params = array(
			'product_id' => $product_id,
		);

		if ( ! empty( $atts['btn_uniq_id'] ) ) {
			$url_params['btn_uniq_id'] = $atts['btn_uniq_id'];
		}

		$prefetch = $this->asp_main->get_setting( 'frontend_prefetch_scripts' );

		if ( $prefetch ) {
			$url_params['ckey'] = ASP_Utils::get_ckey();
		}

		$iframe_url = add_query_arg( $url_params, $base_url );

		$data = array(
			'is_live'                  => $this->asp_main->is_live,
			'product_id'               => $product_id,
			'iframe_url'               => $iframe_url,
			'button_key'               => $button_key,
			'item_price'               => isset( $item_price ) ? $item_price : 0,
			'quantity'                 => $quantity,
			'custom_quantity'          => $custom_quantity,
			'description'              => $description,
			'descrGenerated'           => $descr_generated,
			'shipping'                 => $shipping,
			'tax'                      => $tax,
			'image'                    => $item_logo,
			'currency'                 => $currency,
			'currency_variable'        => $currency_variable,
			'locale'                   => ( empty( $checkout_lang ) ? 'auto' : $checkout_lang ),
			'name'                     => htmlspecialchars_decode( $name ),
			'url'                      => $url,
			'amount'                   => $price_in_cents,
			'billingAddress'           => ( empty( $billing_address ) ? false : true ),
			'shippingAddress'          => ( empty( $shipping_address ) ? false : true ),
			'customer_email'           => $customer_email,
			'uniq_id'                  => $uniq_id,
			'variable'                 => ( empty( $price ) ? true : false ),
			'zeroCents'                => $this->asp_main->zeroCents,
			'addonHooks'               => array(),
			'button_text'              => esc_attr( $button_text ),
			'out_of_stock'             => $out_of_stock,
			'stock_control_enabled'    => $stock_control_enabled,
			'stock_items'              => $stock_items,
			'currencyFormat'           => $display_settings,
			'displayStr'               => $display_str,
			'thankyou_page_url'        => $thankyou_page_url,
			'show_custom_amount_input' => false,
		);

		$data = apply_filters( 'asp-button-output-data-ready', $data, $atts ); 

		$output = '';

		//Let's insert Stripe default stylesheet only when it's needed
		if ( 'stripe-button-el' === $class && ! ( ! $this->compat_mode && $this->stripe_css_inserted ) ) {
			wp_enqueue_style( 'asp-stripe-button-css' );
			$this->stripe_css_inserted = true;
		}

		$output .= $this->get_styles();

		$output .= "<form id = 'asp_ng_form_{$uniq_id}' class='asp-stripe-form' action = '' METHOD = 'POST'> ";

		$output .= $this->get_button_code_new_method( $data );

		$output .= '<div class="asp-child-hidden-fields" style="display: none !important;"></div>';

		$trans_name        = 'stripe-payments-' . $button_key; //Create key using the item name.
		$trans['tax']      = $tax;
		$trans['shipping'] = $shipping;
		$trans['price']    = $price;
		set_transient( $trans_name, $trans, 2 * 3600 ); //Save the price for this item for 2 hours.
		$output .= '</form>';
		//before button filter
		if ( ! $out_of_stock ) {
			$output = apply_filters( 'asp_ng_button_output_before_button', $output, $data, $class );
		}
		$output .= '<div id="asp-all-buttons-container-' . $uniq_id . '" class="asp_all_buttons_container">';
		$output .= $button;
		//after button filter
		if ( ! $out_of_stock ) {
			$output = apply_filters( 'asp_ng_button_output_after_button', $output, $data, $class );
		}
		$output .= '</div>';
		$output .= '<div id="asp-btn-spinner-container-' . $uniq_id . '" class="asp-btn-spinner-container" style="display: none !important">'
			. '<div class="asp-btn-spinner">'
			. '<div></div>'
			. '<div></div>'
			. '<div></div>'
			. '<div></div>'
			. '</div>'
			. '</div>';

		$output .= '<script>';
		$output .= 'var asp_data_' . $uniq_id . ' = ' . wp_json_encode( $data ) . ';';
		$output .= 'if(typeof jQuery!=="undefined") {jQuery(document).ready(function() {new stripeHandlerNG(asp_data_' . $uniq_id . ');});} else { if (typeof wpaspInitOnDocReady==="undefined") {var wpaspInitOnDocReady=[];} wpaspInitOnDocReady.push(asp_data_' . $uniq_id . ');}';
		$output .= '</script>';

		$prefetch = $this->asp_main->get_setting( 'frontend_prefetch_scripts' );
		if ( $prefetch ) {
			$this->asp_main->footer_scripts .= '<link rel="prefetch" as="document" href="' . $data['iframe_url'] . '" />';

			if ( empty( $this->asp_main->sc_scripts_prefetched ) ) {
				$this->asp_main->footer_scripts .= '<link rel="dns-prefetch" href="https://q.stripe.com" />';
				$this->asp_main->footer_scripts .= '<link rel="prefetch" href="https://js.stripe.com/v3/" />';
				if ( ! defined( 'WP_ASP_DEV_MODE' ) ) {
					$this->asp_main->footer_scripts .= '<link rel="prefetch" as="style" href="' . WP_ASP_PLUGIN_URL . '/public/views/templates/default/pp-combined.min.css?ver=' . WP_ASP_PLUGIN_VERSION . '" />';
					$this->asp_main->footer_scripts .= '<link rel="prefetch" as="script" href="' . WP_ASP_PLUGIN_URL . '/public/assets/js/pp-handler.min.js?ver=' . WP_ASP_PLUGIN_VERSION . '" />';
				} else {
					$this->asp_main->footer_scripts .= '<link rel="prefetch" as="style" href="' . WP_ASP_PLUGIN_URL . '/public/views/templates/default/pure.css?ver=' . WP_ASP_PLUGIN_VERSION . '" />';
					$this->asp_main->footer_scripts .= '<link rel="prefetch" as="style" href="' . WP_ASP_PLUGIN_URL . '/public/views/templates/default/pp-style.css?ver=' . WP_ASP_PLUGIN_VERSION . '" />';
					$this->asp_main->footer_scripts .= '<link rel="prefetch" as="script" href="' . WP_ASP_PLUGIN_URL . '/public/assets/js/pp-handler.js?ver=' . WP_ASP_PLUGIN_VERSION . '" />';
				}
			}
		}
		return $output;
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-asp-shortcode-ng.php

Accept Stripe Payments [asp_show_all_products] Shortcode

The Stripe Payments shortcode ‘asp_show_all_products’ displays all the products configured in the Stripe Payments plugin. It allows customization such as sorting and searching products. The shortcode uses parameters like ‘items_per_page’, ‘sort_by’, ‘sort_order’, ‘template’, ‘search_box’ to modify the output. It also handles pagination, making it suitable for large product lists.

Shortcode: [asp_show_all_products]

Parameters

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

  • items_per_page – Defines the number of products displayed per page.
  • sort_by – Sets the parameter by which products are sorted.
  • sort_order – Determines the order of sorting, ascending or descending.
  • template – Specifies the template to be used for displaying products.
  • search_box – Enables or disables the search box on the products page.

Examples and Usage

Basic example – Display all products with default settings

[asp_show_all_products /]

Advanced examples

Display all products, but limit the items per page to 10, sort by price in ascending order, and use a custom template.

[asp_show_all_products items_per_page="10" sort_by="price" sort_order="asc" template="custom_template" /]

Display all products with a search box, sort by product id in descending order, and limit the items per page to 20.

[asp_show_all_products search_box="1" sort_by="id" sort_order="desc" items_per_page="20" /]

Show all products with a search box, sort by product name in ascending order, and use a custom template.

[asp_show_all_products search_box="1" sort_by="name" sort_order="asc" template="custom_template" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'asp_show_all_products', array( &$this, 'shortcode_show_all_products' ) );

Shortcode PHP function:

function shortcode_show_all_products( $params ) {

		$params = shortcode_atts(
			array(
				'items_per_page' => '30',
				'sort_by'        => 'none',
				'sort_order'     => 'desc',
				'template'       => '',
				'search_box'     => '1',
			),
			$params,
			'asp_show_all_products'
		);

		//if user has changed sort by from UI
		$sort_by = isset( $_GET['asp-sortby'] ) ? sanitize_text_field( stripslashes ( $_GET['asp-sortby'] ) ) : '';

		include_once WP_ASP_PLUGIN_PATH . 'public/views/all-products/default/template.php';

		$page = filter_input( INPUT_GET, 'asp_page', FILTER_SANITIZE_NUMBER_INT );

		$page = empty( $page ) ? 1 : $page;

		$order_by = isset( $params['sort_by'] ) ? ( $params['sort_by'] ) : 'none';

		$sort_direction = isset( $params['sort_order'] ) ? strtoupper( $params['sort_order'] ) : 'DESC';

		if($sort_by)
		{
			$order_by=explode("-",$sort_by)[0];
			$sort_direction=isset(explode("-",$sort_by)[1])?explode("-",$sort_by)[1]:"asc";
		}
		else{
			//set default to latest sort
			$order_by="id";			
		}

		$q = array(
			'post_type'      => ASPMain::$products_slug,
			'post_status'    => 'publish',
			'posts_per_page' => isset( $params['items_per_page'] ) ? $params['items_per_page'] : 30,
			'paged'          => $page,
			'orderby'        => $order_by,
			'order'          => $sort_direction,
		);

		//handle search

		$search = isset( $_GET['asp_search'] ) ? sanitize_text_field( stripslashes ( $_GET['asp_search'] ) ) : '';

		$search = empty( $search ) ? false : $search;

		if ( $search !== false ) {
			$q['s'] = $search;
		}

		if( $q["orderby"] == "price" ) {
			add_filter( 'posts_orderby', array(__CLASS__,'asp_orderby_price_callback' ));		
		}

		$products = new WP_Query( $q );

		if( $q["orderby"] == "price" ) {
			remove_filter( 'posts_orderby',array(__CLASS__,'asp_orderby_price_callback')  );
		}

		if ( ! $products->have_posts() ) {
			//query returned no results. Let's see if that was a search query
			if ( $search === false ) {
				//that wasn't search query. That means there is no products configured
				wp_reset_postdata();
				return __( 'No products have been configured yet', 'stripe-payments' );
			}
		}

		$search_box = ! empty( $params['search_box'] ) ? $params['search_box'] : false;

		if ( $search_box ) {
			if ( $search !== false ) {
				$tpl['clear_search_url']   = esc_url( remove_query_arg( array( 'asp_search', 'asp_page' ) ) );
				$tpl['search_result_text'] = $products->found_posts === 0 ? __( 'Nothing found for', 'stripe-payments' ) . ' "%s".' : __( 'Search results for', 'stripe-payments' ) . ' "%s".';
				$tpl['search_result_text'] = sprintf( $tpl['search_result_text'], htmlentities( $search ) );
				$tpl['search_term']        = htmlentities( $search );
			} else {
				$tpl['search_result_text']  = '';
				$tpl['clear_search_button'] = '';
				$tpl['search_term']         = '';
			}
		} else {
			$tpl['search_box'] = '';
		}

		$tpl['products_list'] .= $tpl['products_row_start'];
		$i                     = $tpl['products_per_row']; //items per row

		while ( $products->have_posts() ) {
			$products->the_post();
			$i --;
			if ( $i < 0 ) { //new row
				$tpl['products_list'] .= $tpl['products_row_end'];
				$tpl['products_list'] .= $tpl['products_row_start'];
				$i                     = $tpl['products_per_row'] - 1;
			}

			$id = get_the_ID();			

			$thumb_url = get_post_meta( $id, 'asp_product_thumbnail', true );
			if ( ! $thumb_url ) {
				$thumb_url = WP_ASP_PLUGIN_URL . '/assets/product-thumb-placeholder.png';
			}

			$view_btn = str_replace( '%[product_url]%', get_permalink(), $tpl['view_product_btn'] );

			$price = get_post_meta( $id, 'asp_product_price', true );
			$curr  = get_post_meta( $id, 'asp_product_currency', true );

			if ( empty( $plan_id ) ) {
				//let's apply filter so addons can change price, currency and shipping if needed
				$price_arr = array(
					'price'    => $price,
					'currency' => $curr,
					'shipping' => empty( $shipping ) ? false : $shipping,
				);
				$price_arr = apply_filters( 'asp_modify_price_currency_shipping', $price_arr );
				extract( $price_arr, EXTR_OVERWRITE );
				$curr = $currency;
			}

			$price_orig = $price;

			$price = AcceptStripePayments::formatted_price( $price, $curr );
			if ( empty( $price ) ) {
				$price = '&nbsp';
			}

			$constr_price_var = get_post_meta( $id, 'asp_product_hide_amount_input', true );

			if ( empty( $price_orig ) && ! empty( $constr_price_var ) ) {
				$price = __( 'Variable', 'stripe-payments' );
			}

			$item_tags = array( 'price' => $price );

			$item_tags = apply_filters( 'asp_product_tpl_tags_arr', $item_tags, $id );

			$price = $item_tags['price'];

			$item = str_replace(
				array(
					'%[product_id]%',
					'%[product_name]%',
					'%[product_thumb]%',
					'%[view_product_btn]%',
					'%[product_price]%',
				),
				array(
					$id,
					get_the_title(),
					$thumb_url,
					$view_btn,
					$price,
				),
				$tpl['products_item']
			);

			$tpl['products_list'] .= $item;
		}

		$tpl['products_list'] .= $tpl['products_row_end'];

		//pagination

		$tpl['pagination_items'] = '';

		$pages = $products->max_num_pages;

		if ( $pages > 1 ) {
			$i = 1;

			while ( $i <= $pages ) {
				if ( $i != $page ) {
					$url = esc_url( add_query_arg( 'asp_page', $i ) );
					$str = str_replace( array( '%[url]%', '%[page_num]%' ), array( $url, $i ), $tpl['pagination_item'] );
				} else {
					$str = str_replace( '%[page_num]%', $i, $tpl['pagination_item_current'] );
				}
				$tpl['pagination_items'] .= $str;
				$i ++;
			}
		}

		if ( empty( $tpl['pagination_items'] ) ) {
			$tpl['pagination'] = '';
		}

		wp_reset_postdata();

		//Build template
		foreach ( $tpl as $key => $value ) {
			$tpl['page'] = str_replace( '_%' . $key . '%_', $value, $tpl['page'] );
		}

		$output = '<div class="wpec_shop_products">'.$tpl['page'].'</div>';
		return $output;
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-shortcode-asp.php

Accept Stripe Payments [accept_stripe_payment_checkout] Shortcode

The Stripe Payments plugin shortcode ‘accept_stripe_payment_checkout’ facilitates the checkout process. It retrieves session data, displays error messages, and generates the output for successful transactions.

Shortcode: [accept_stripe_payment_checkout]

Examples and Usage

Basic example – Embeds Stripe payment checkout in your page or post.

[accept_stripe_payment_checkout /]

Advanced examples

Displays Stripe payment checkout with custom error message. If the system is not able to complete the payment, the custom error message will be displayed.

[accept_stripe_payment_checkout error_msg="Sorry, your payment could not be processed at this time. Please try again later." /]

Displays Stripe payment checkout with a custom thank you message after successful payment. The message will be displayed on the checkout page.

[accept_stripe_payment_checkout thank_you_msg="Thank you for your purchase! Your payment has been successfully processed." /]

Displays Stripe payment checkout with custom error and thank you messages.

[accept_stripe_payment_checkout error_msg="Sorry, your payment could not be processed at this time. Please try again later." thank_you_msg="Thank you for your purchase! Your payment has been successfully processed." /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'accept_stripe_payment_checkout', array( &$this, 'shortcode_accept_stripe_payment_checkout' ) );

Shortcode PHP function:

function shortcode_accept_stripe_payment_checkout( $atts, $content = '' ) {
		if ( ! defined( 'DONOTCACHEPAGE' ) ) {
			define( 'DONOTCACHEPAGE', true );
		}

		$aspData = array();
		$sess    = ASP_Session::get_instance();
		$aspData = $sess->get_transient_data( 'asp_data' );
		if ( empty( $aspData ) ) {
			// no session data, let's display nothing for now
			return;
		}
		if ( empty( $content ) ) {
			//this is old shortcode. Let's display the default output for backward compatability
			if ( isset( $aspData['error_msg'] ) && ! empty( $aspData['error_msg'] ) ) {
				//some error occurred, let's display it
				return __( 'System was not able to complete the payment.', 'stripe-payments' ) . ' ' . $aspData['error_msg'];
			}
			$output  = '';
			$output .= '<p class="asp-thank-you-page-msg1">' . __( 'Thank you for your payment.', 'stripe-payments' ) . '</p>';
			$output .= '<p class="asp-thank-you-page-msg2">' . __( "Here's what you purchased: ", 'stripe-payments' ) . '</p>';
			$output .= '<div class="asp-thank-you-page-product-name">' . __( 'Product Name', 'stripe-payments' ) . ': {item_name}' . '</div>';
			$output .= '<div class="asp-thank-you-page-qty">' . __( 'Quantity', 'stripe-payments' ) . ': {item_quantity}' . '</div>';
			$output .= '<div class="asp-thank-you-page-item-price">' . __( 'Item Price', 'stripe-payments' ) . ': {item_price_curr}' . '</div>';
			//check if there are any additional items available like tax and shipping cost
			$output .= AcceptStripePayments::gen_additional_items( $aspData, '<br />' );
			$output .= '<hr />';
			$output .= '<div class="asp-thank-you-page-total-amount">' . __( 'Total Amount', 'stripe-payments' ) . ': {paid_amount_curr}' . '</div>';
			$output .= '<br />';
			$output .= '<div class="asp-thank-you-page-txn-id">' . __( 'Transaction ID', 'stripe-payments' ) . ': {transaction_id}' . '</div>';

			$download_str = '';
			if ( ! empty( $aspData['item_url'] ) ) {
				$download_str .= "<br /><div class='asp-thank-you-page-download-link'>";
				$download_str .= _x( 'Please ', "Is a part of 'Please click here to download'", 'stripe-payments' ) . "<a href='{item_url}'>" . _x( 'click here', "Is a part of 'Please click here to download'", 'stripe-payments' ) . '</a>' . _x( ' to download.', "Is a part of 'Please click here to download'", 'stripe-payments' );
				$download_str .= '</div>';
			}

			//variations download links if needed
			if ( ! empty( $aspData['var_applied'] ) ) {
				$download_var_str  = '';
				$has_download_link = false;
				$download_var_str .= "<br /><div class='asp-thank-you-page-download-link'>";
				$download_var_str .= '<span>' . __( 'Download links', 'stripe-payments' ) . ':</span><br/>';
				$download_txt      = __( 'Click here to download', 'stripe-payments' );
				$link_tpl          = '<a href="%s">%s</a><br/>';
				foreach ( $aspData['var_applied'] as $var ) {
					if ( ! empty( $var['url'] ) ) {
						$has_download_link = true;
						$download_var_str .= sprintf( $link_tpl, $var['url'], $download_txt );
					}
				}
				$download_var_str .= '</div>';
				if ( $has_download_link ) {
					$download_str .= $download_var_str;
				}
			}
			$output .= $download_str;

			$output = apply_filters( 'asp_stripe_payments_checkout_page_result', $output, $aspData ); //Filter that allows you to modify the output data on the checkout result page

			$output = $this->apply_content_tags( $output, $aspData );

			$output .= '<style>.asp-thank-you-page-msg-wrap {background: #dff0d8; border: 1px solid #C9DEC1; margin: 10px 0px; padding: 15px;}</style>';
			$wrap    = "<div class='asp-thank-you-page-wrap'>";
			$wrap   .= "<div class='asp-thank-you-page-msg-wrap'>";
			$output  = $wrap . $output;
			$output .= '</div>'; //end of .asp-thank-you-page-msg-wrap
			$output .= '</div>'; //end of .asp-thank-you-page-wrap

			return $output;
		}
		if ( isset( $aspData['error_msg'] ) && ! empty( $aspData['error_msg'] ) ) {
			//some error occurred. Let's check if we have [accept_stripe_payment_checkout_error] shortcode on page
			$page_content = get_the_content();
			if ( ! empty( $page_content ) && ! has_shortcode( $page_content, 'accept_stripe_payment_checkout_error' ) ) {
				//no error output shortcode found. Let's output default error message
				return __( 'System was not able to complete the payment.', 'stripe-payments' ) . ' ' . $aspData['error_msg'];
			}
			return;
		}

		$content = apply_filters( 'asp_stripe_payments_checkout_page_result', $content, $aspData );

		$content = $this->apply_content_tags( do_shortcode( $content ), $aspData );
		return $content;
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-shortcode-asp.php

Accept Stripe Payments [accept_stripe_payment_checkout_error] Shortcode

The ‘accept_stripe_payment_checkout_error’ shortcode is used to display error messages during Stripe payment checkout. It retrieves any error message stored in the session data and displays it to the user. If no error occurred, nothing is displayed.

Shortcode: [accept_stripe_payment_checkout_error]

Examples and Usage

Basic example – Utilizes the shortcode to display an error message from the Stripe payment checkout. If there’s an error during the checkout process, the error message will be shown.

[accept_stripe_payment_checkout_error /]

Advanced examples

Embedding the shortcode within a text to display the error message. The error message will be integrated into the content, providing a seamless user experience.

[accept_stripe_payment_checkout_error]Oops, there seems to be an issue with your payment. Please try again.[/accept_stripe_payment_checkout_error]

Using the shortcode with additional attributes to customize the error message. This allows for a more personalized and descriptive error message.

[accept_stripe_payment_checkout_error error_msg="Your payment could not be processed at this time. Please check your card details and try again." /]

Please note, the additional attributes functionality would need to be added in the PHP function ‘shortcode_accept_stripe_payment_checkout_error’ to allow for customizable error messages.

PHP Function Code

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

Shortcode line:

add_shortcode( 'accept_stripe_payment_checkout_error', array( &$this, 'shortcode_accept_stripe_payment_checkout_error' ) );

Shortcode PHP function:

function shortcode_accept_stripe_payment_checkout_error( $atts, $content = '' ) {
		$aspData = array();
		$sess    = ASP_Session::get_instance();
		$aspData = $sess->get_transient_data( 'asp_data' );
		if ( empty( $aspData ) ) {
			// no session data, let's display nothing for now
			return;
		}
		if ( isset( $aspData['error_msg'] ) && ! empty( $aspData['error_msg'] ) ) {
			//some error occurred. Let's display error message
			$content = $this->apply_content_tags( do_shortcode( $content ), $aspData );
			return $content;
		}
		// no error occurred - we don't display anything
		return;
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-shortcode-asp.php

Accept Stripe Payments [asp_show_my_transactions] Shortcode

The Stripe Payments shortcode, ‘asp_show_my_transactions’, displays a user’s transaction history. It allows customization of items per page and the ability to show or hide subscription cancellation and download links.

Shortcode: [asp_show_my_transactions]

Parameters

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

  • items_per_page – Determines the number of transactions displayed per page
  • show_subscription_cancel – If set to 1, displays a subscription cancellation option
  • show_download_link – If set to 1, includes a download link in the transaction list

Examples and Usage

Basic example – The given shortcode displays the user’s transactions with default parameters. It shows 20 items per page and includes a download link for each transaction.

[asp_show_my_transactions]

Advanced examples

Here, the shortcode is used to display only 10 transactions per page, without a download link for each transaction.

[asp_show_my_transactions items_per_page="10" show_download_link="0"]

In this example, the shortcode displays 30 transactions per page with a download link for each transaction and also includes a subscription cancellation option.

[asp_show_my_transactions items_per_page="30" show_download_link="1" show_subscription_cancel="1"]

PHP Function Code

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

Shortcode line:

add_shortcode( 'asp_show_my_transactions', array( $this, 'show_user_transactions' ) );

Shortcode PHP function:

function show_user_transactions( $atts ) {
		$atts = shortcode_atts(
			array(
				'items_per_page'           => '20',
				'show_subscription_cancel' => 0,
				'show_download_link'       => 1,
			),
			$atts,
			'asp_show_my_transactions'
		);
		require_once WP_ASP_PLUGIN_PATH . 'includes/shortcodes/show-user-transactions.php';
		$scClass = new AcceptStripePayments_scUserTransactions();
		return $scClass->process_shortcode( $atts );
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-shortcode-asp.php

Accept Stripe Payments [asp_available_quantity] Shortcode

The Stripe Payments shortcode ‘asp_available_quantity’ displays the available quantity of a specific product. It validates the product ID and if stock management is enabled, it shows the quantity left. If not, it displays ‘Unlimited’.

Shortcode: [asp_available_quantity]

Parameters

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

  • id – The unique identifier of the product

Examples and Usage

Basic example – Displays the available quantity of a product by referencing the product ID.

[asp_available_quantity id=1 /]

Advanced Examples

Using the shortcode to display the available quantity of a product by referencing the product ID. If the product ID is invalid or the product doesn’t exist, it will display an error message.

[asp_available_quantity id=100 /]

Using the shortcode to display the available quantity of a product by referencing the product ID. If the product doesn’t have a stock limit, it will display ‘Unlimited’.

[asp_available_quantity id=2 /]

Please note that the ‘id’ parameter in the shortcode refers to the product ID in your WordPress database. If the product ID is invalid or the product doesn’t exist, the shortcode will return an error message. If the product doesn’t have a stock limit, the shortcode will return ‘Unlimited’.

PHP Function Code

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

Shortcode line:

add_shortcode( 'asp_available_quantity', array( $this, 'show_available_quantity' ) );

Shortcode PHP function:

function show_available_quantity( $atts ) {
		if ( ! isset( $atts['id'] ) || ! is_numeric( $atts['id'] ) ) {
			$error_msg  = '<div class="asp_error_msg" style="color: red;">';
			$error_msg .= 'Error: product ID is invalid.';
			$error_msg .= '</div>';
			return $error_msg;
		}
		$id   = $atts['id'];
		$post = get_post( $id );
		if ( ! $post || get_post_type( $id ) != ASPMain::$products_slug ) {
			$error_msg  = '<div class="asp_error_msg" style="color: red;">';
			$error_msg .= "Error: invalid product ID " . $id;
			$error_msg .= '</div>';
			return $error_msg;
		}
		
		$available_quantity = esc_attr(get_post_meta( $id, 'asp_product_stock_items', true ));
		$stock_enable = esc_attr(get_post_meta( $id, 'asp_product_enable_stock', true ));

		$output  = '<span class="asp_available_quantity">';
		$output  .= $stock_enable ? $available_quantity : 'Unlimited';
		$output  .= '</span>';
		return $output;
	}

Code file location:

stripe-payments/stripe-payments/includes/shortcodes/class-shortcode-asp.php

Conclusion

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