Home / Admin / WP Simple Pay: {subtotal} Smart Tag
Duplicate Snippet

Embed Snippet on Your Site

WP Simple Pay: {subtotal} Smart Tag

Adds a {subtotal} Smart Tag.

Code Preview
php
<?php
/**
 * @link https://library.wpcode.com/snippet/r5plvkeo/
 */
add_filter(
	'simpay_payment_details_template_tags',
	function( $smart_tags ) {
		$smart_tags[] = 'subtotal';
		return $smart_tags;
	}
);
add_filter(
	'simpay_payment_confirmation_template_tag_subtotal',
	function( $value, $payment_confirmation_data ) {
		$subscription = current( $payment_confirmation_data['subscriptions'] );
		if ( $subscription ) {
			$payment = $subscription->latest_invoice->payment_intent;
		} else {
			$payment = current( $payment_confirmation_data['paymentintents'] );
		}
		return simpay_format_currency(
			$payment->metadata->simpay_unit_amount * $payment->metadata->simpay_quantity,
			$payment->currency
		);
	},
	10,
	2
);

Comments

Add a Comment