Home / Admin / WP Simple Pay: Multiple Price Option Label Smart Tag
Duplicate Snippet

Embed Snippet on Your Site

WP Simple Pay: Multiple Price Option Label Smart Tag

Use the Smart Tag {selected-price-label} to display the Label of the selected Price Option when there are multiple price options. Works for One-Time and Subscriptions.

Code Preview
php
<?php
add_filter(
	'simpay_payment_details_template_tags',
	function( $smart_tags ) {
		$smart_tags[] = 'selected-price-label';
		return $smart_tags;
	}
);
add_filter(
	'simpay_payment_confirmation_template_tag_selected-price-label',
	function( $value, $payment_confirmation_data ) {
		if ( empty( $payment_confirmation_data['subscriptions'] ) ) {
			$payments = $payment_confirmation_data['paymentintents'];
			$payment = current( $payments );
			return $payment->description;
		}
		$subscriptions = $payment_confirmation_data['subscriptions'];
		$subscription = current( $subscriptions );
		$purchased = $subscription->metadata->simpay_price_instances;
		$purchased_data = explode(':', $purchased);
		$purchased_instance_id = $purchased_data[0];
		$form = $payment_confirmation_data['form'];
		$prices = simpay_get_payment_form_prices( $form );
		foreach ( $prices as $price ) {
			if ( $price->instance_id === $purchased_instance_id ) {
				return $price->label;
			}
		}
	},
	10,
	2
);

Comments

Add a Comment