Home / Archive / EDD Smart Tags
Duplicate Snippet

Embed Snippet on Your Site

EDD Smart Tags

This snippet adds 2 smart tags that you can use on the EDD confirmation page: Order Total and Order Items Count.

<10
Code Preview
php
<?php
add_filter( 'wpcode_smart_tags', function ( $tags ) {
	$tags['edd'] = array(
		'label' => 'Easy Digital Downloads',
		'tags'  => array(
			'edd_order_total'       => array(
				'label'    => 'Order Total',
				'function' => 'wpcode_custom_get_edd_order_total',
			),
			'edd_order_items_count' => array(
				'label'    => 'Order Items Count',
				'function' => 'wpcode_custom_get_edd_order_items_count',
			),
		),
	);
	return $tags;
} );
function wpcode_custom_get_edd_order_total() {
	if ( ! function_exists( 'edd_get_order' ) ) {
		return '';
	}
	global $edd_receipt_args;
	if ( empty( $edd_receipt_args['id'] ) ) {
		return '';
	}
	$order = edd_get_order( $edd_receipt_args['id'] );
	if ( empty( $order ) ) {
		return '';
	}
	return edd_get_payment_amount( $order->id );
}
function wpcode_custom_get_edd_order_items_count() {
	if ( ! function_exists( 'edd_get_order' ) ) {
		return 0;
	}
	global $edd_receipt_args;
	if ( empty( $edd_receipt_args['id'] ) ) {
		return 0;
	}
	$order = edd_get_order( $edd_receipt_args['id'] );
	if ( empty( $order ) ) {
		return 0;
	}
	return count( $order->get_items() );
}

Comments

Add a Comment