Easy Digital Downloads Shortcodes

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

Before starting, here is an overview of the Easy Digital Downloads Plugin and the shortcodes it provides:

Plugin Icon
Easy Digital Downloads – Sell Digital Files (eCommerce Store & Payments Made Easy)

"Easy Digital Downloads is a convenient plugin for eCommerce stores. It simplifies the selling of digital files and streamlines payment processes. This plugin makes eCommerce easy."

★★★★☆ (508) Active Installs: 50000+ Tested with: 6.3.2 PHP Version: 7.4
Included Shortcodes:
  • [purchase_link]
  • [download_history]
  • [purchase_history]
  • [download_checkout]
  • [download_cart]
  • [edd_login]
  • [edd_register]
  • [download_discounts]
  • [purchase_collection]
  • [downloads]
  • [edd_price]
  • [edd_receipt]
  • [edd_profile_editor]

Easy Digital Downloads [purchase_link] Shortcode

The ‘purchase_link’ shortcode from Easy Digital Downloads plugin is designed to generate a purchase link for a specific digital product. It accepts various parameters like ‘id’, ‘price_id’, ‘sku’, ‘price’, ‘direct’, ‘text’, ‘style’, ‘color’, ‘class’, ‘form_id’. The shortcode first checks if a SKU is provided. If so, it fetches the download by SKU. If an ‘id’ is provided instead, it fetches the download by ‘id’. The shortcode then generates a purchase link using these parameters. This enables customization of the purchase link for various digital products.

Shortcode: [purchase_link]

Parameters

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

  • id – Unique identifier of the digital download
  • price_id – Identifier for the specific price variant
  • sku – Stock Keeping Unit identifier for the product
  • price – Toggle to show or hide the price. ‘1’ to show, ‘0’ to hide
  • direct – ‘1’ for direct purchase, ‘0’ to add to cart
  • text – Custom text for the purchase button
  • style – Style of the purchase button
  • color – Color class for the purchase button
  • class – Custom CSS class for the purchase button
  • form_id – Unique identifier of the form

Examples and Usage

Basic example – A simple usage of the ‘purchase_link’ shortcode to display a purchase button for a specific digital product. The product is identified by its post ID.

[purchase_link id=123 /]

Advanced examples

Displaying a purchase button with a custom text. The ‘text’ attribute allows you to customize the text displayed on the purchase button.

[purchase_link id=123 text="Buy this awesome product now!" /]

Using the shortcode to display a purchase button for a product with a specific SKU. The ‘sku’ attribute allows you to reference a product by its SKU instead of its post ID.

[purchase_link sku="PROD001" /]

Enabling direct purchase with the ‘direct’ attribute. When set to ‘1’, the ‘direct’ attribute allows customers to bypass the cart and go straight to checkout.

[purchase_link id=123 direct=1 /]

Displaying a purchase button with a specific style and color. The ‘style’ and ‘color’ attributes allow you to customize the appearance of the purchase button.

[purchase_link id=123 style="button" color="blue" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'purchase_link', 'edd_download_shortcode' );

Shortcode PHP function:

function edd_download_shortcode( $atts, $content = null ) {
	global $post;

	$post_id = is_object( $post ) ? $post->ID : 0;

	$atts = shortcode_atts( array(
		'id'       => $post_id,
		'price_id' => isset( $atts['price_id'] ) ? $atts['price_id'] : false,
		'sku'      => '',
		'price'    => '1',
		'direct'   => '0',
		'text'     => '',
		'style'    => edd_get_option( 'button_style', 'button' ),
		'color'    => edd_get_button_color_class(),
		'class'    => 'edd-submit',
		'form_id'  => '',
	),
	$atts, 'purchase_link' );

	// Override text only if not provided / empty
	if ( ! $atts['text'] ) {
		if( $atts['direct'] == '1' || $atts['direct'] == 'true' ) {
			$atts['text'] = edd_get_option( 'buy_now_text', __( 'Buy Now', 'easy-digital-downloads' ) );
		} else {
			$atts['text'] = edd_get_option( 'add_to_cart_text', __( 'Purchase', 'easy-digital-downloads' ) );
		}
	}

	if( ! empty( $atts['sku'] ) ) {

		$download = edd_get_download_by( 'sku', $atts['sku'] );

		if ( $download ) {
			$atts['download_id'] = $download->ID;
		}

	} elseif( isset( $atts['id'] ) ) {

		// Edd_get_purchase_link() expects the ID to be download_id since v1.3
		$atts['download_id'] = $atts['id'];

		$download = edd_get_download( $atts['download_id'] );

	}

	if ( $download ) {
		return edd_get_purchase_link( $atts );
	}
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [download_history] Shortcode

The Easy Digital Downloads shortcode, ‘download_history’, allows logged-in users to view their download history. If the user’s verification is pending, it displays an account pending template.

Shortcode: [download_history]

Examples and Usage

Basic example – A simple use case of the ‘download_history’ shortcode. It displays the download history of the logged-in user.

[download_history /]

Advanced examples

Using the shortcode to display a specific template part based on the verification status of the user. If the user is verified, it will display the download history. If not, it will display a pending account message.


add_shortcode( 'download_history', 'edd_download_history' );
function edd_download_history() {
	if ( is_user_logged_in() ) {
		ob_start();

		if( ! edd_user_pending_verification() ) {

			edd_get_template_part( 'history', 'downloads' );

		} else {

			edd_get_template_part( 'account', 'pending' );

		}

		return ob_get_clean();
	}
}

Note: The ‘download_history’ shortcode does not accept any parameters or attributes, as it is dependent on the logged-in user’s status and not any passed values.

PHP Function Code

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

Shortcode line:

add_shortcode( 'download_history', 'edd_download_history' );

Shortcode PHP function:

function edd_download_history() {
	if ( is_user_logged_in() ) {
		ob_start();

		if( ! edd_user_pending_verification() ) {

			edd_get_template_part( 'history', 'downloads' );

		} else {

			edd_get_template_part( 'account', 'pending' );

		}

		return ob_get_clean();
	}
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [purchase_history] Shortcode

The ‘Easy Digital Downloads’ plugin shortcode, ‘purchase_history’, retrieves and displays the user’s purchase history. If the user’s account is not pending verification, it shows the ‘history’ template part. If the account is pending, it shows the ‘pending’ template part.

Shortcode: [purchase_history]

Examples and Usage

Basic example – The shortcode ‘purchase_history’ gets the purchase history of the current logged in user.

[purchase_history /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'purchase_history', 'edd_purchase_history' );

Shortcode PHP function:

function edd_purchase_history() {
	ob_start();

	if( ! edd_user_pending_verification() ) {

		edd_get_template_part( 'history', 'purchases' );

	} else {

		edd_get_template_part( 'account', 'pending' );

	}

	return ob_get_clean();
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [download_checkout] Shortcode

The Easy Digital Downloads shortcode ‘download_checkout’ initiates the checkout form. Using add_shortcode( ‘download_checkout’, ‘edd_checkout_form_shortcode’ ), the function ‘edd_checkout_form_shortcode’ is executed. This function returns the checkout form, providing a seamless checkout experience for digital products.

Shortcode: [download_checkout]

Examples and Usage

Basic example – A simple usage of the ‘download_checkout’ shortcode to display the checkout form on a page or post.

[download_checkout /]

For advanced examples, we can use the ‘download_checkout’ shortcode with additional parameters. However, please note that the ‘download_checkout’ shortcode doesn’t actually accept any parameters according to the related PHP function. The function ‘edd_checkout_form_shortcode’ doesn’t have any attributes to modify the output. Thus, the shortcode will always return the checkout form without any modifications. But for the sake of example, if there were parameters, they might look something like this:

Advanced examples

Using the shortcode to display a specific download’s checkout form by referencing the download ID. The form will load the checkout form for the specified download.

[download_checkout id="123" /]

Using the shortcode to display a specific download’s checkout form by referencing the download ID and specifying a custom class for styling purposes.

[download_checkout id="123" class="my-custom-class" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'download_checkout', 'edd_checkout_form_shortcode' );

Shortcode PHP function:

function edd_checkout_form_shortcode( $atts, $content = null ) {
	return edd_checkout_form();
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [download_cart] Shortcode

The Easy Digital Downloads ‘download_cart’ shortcode adds a shopping cart to your site. It allows users to view their selected downloads before purchasing. This shortcode calls the ‘edd_cart_shortcode’ function, which returns the ‘edd_shopping_cart()’ function. This function displays the user’s current shopping cart.

Shortcode: [download_cart]

Examples and Usage

Basic Example – The following shortcode displays the EDD shopping cart, allowing users to see their selected downloads before making a purchase.

[download_cart /]

Advanced Examples

Even though the given shortcode does not accept any parameters, we can add some by modifying the PHP function. Let’s assume we have modified the ‘edd_cart_shortcode’ function to accept ‘title’ and ‘button_text’ parameters. Here’s how we can use them:

Displaying the EDD shopping cart with a custom title and button text. The title will be displayed above the cart, and the button text will be used for the checkout button.

[download_cart title="Your Shopping Cart" button_text="Proceed to Checkout" /]

Note: The above examples assume that you have modified the ‘edd_cart_shortcode’ function to accept and use the ‘title’ and ‘button_text’ parameters. If you haven’t done so, these parameters will have no effect.

PHP Function Code

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

Shortcode line:

add_shortcode( 'download_cart', 'edd_cart_shortcode' );

Shortcode PHP function:

function edd_cart_shortcode( $atts, $content = null ) {
	return edd_shopping_cart();
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [edd_login] Shortcode

The Easy Digital Downloads (EDD) shortcode ‘edd_login’ enables a login form on your site. It uses the ‘edd_login_form_shortcode’ function to extract a redirect attribute. If a redirect page is specified, it redirects to that page post-login. If not, it checks for a ‘login_redirect_page’ option. If this option is unavailable, it looks for a ‘purchase_history_page’ option. If all options are absent, it redirects to the home page post-login. This shortcode is handy for customizing user login experiences.

Shortcode: [edd_login]

Parameters

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

  • redirect – Specifies the page to redirect to after login

Examples and Usage

Basic example – Provides a simple login form using the ‘edd_login’ shortcode without any parameters. The login form will redirect to the default pages set in the Easy Digital Downloads settings.

[edd_login /]

Advanced examples

Utilizing the ‘redirect’ attribute in the shortcode to specify a custom redirect page after login. The page is identified by its unique ID. If the page ID is not found, it will redirect to the homepage or the default pages set in the Easy Digital Downloads settings.

[edd_login redirect=123 /]

Using the ‘redirect’ attribute to specify a custom redirect page after login. The page is identified by its slug. If the page slug is not found, it will redirect to the homepage or the default pages set in the Easy Digital Downloads settings.

[edd_login redirect="my-account" /]

Please note that in the above examples, replace 123 and “my-account” with your actual page ID or slug.

PHP Function Code

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

Shortcode line:

add_shortcode( 'edd_login', 'edd_login_form_shortcode' );

Shortcode PHP function:

function edd_login_form_shortcode( $atts, $content = null ) {
	$redirect = '';

	extract( shortcode_atts( array(
		'redirect' => $redirect
	), $atts, 'edd_login' ) );

	if ( empty( $redirect ) ) {
		$login_redirect_page = edd_get_option( 'login_redirect_page', '' );

		if ( ! empty( $login_redirect_page ) ) {
			$redirect = get_permalink( $login_redirect_page );
		}
	}

	if ( empty( $redirect ) ) {
		$purchase_history = edd_get_option( 'purchase_history_page', 0 );

		if ( ! empty( $purchase_history ) ) {
			$redirect = get_permalink( $purchase_history );
		}
	}

	if ( empty( $redirect ) ) {
		$redirect = home_url();
	}

	return edd_login_form( $redirect );
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [edd_register] Shortcode

The Easy Digital Downloads (EDD) shortcode ‘edd_register’ is designed to generate a user registration form. This shortcode redirects users to the home page after registration. If a purchase history page is set in EDD options, it redirects users there instead.

Shortcode: [edd_register]

Parameters

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

  • redirect – URL to direct users to after registration

Examples and Usage

Basic example – The shortcode ‘edd_register’ is used to display the registration form. In its simplest form, it doesn’t require any parameters and will redirect the user to the home page after registration.

[edd_register /]

Advanced examples

A more advanced use of the ‘edd_register’ shortcode is to specify a custom redirect URL. This will direct the user to a specific page after they have registered. For example, you might want to redirect them to a ‘Thank You’ page or a specific product page.

[edd_register redirect="https://www.yoursite.com/thank-you" /]

Another advanced usage is to redirect the user to their purchase history page after registration. To do this, you need to set the ‘redirect’ parameter to the URL of the purchase history page.

[edd_register redirect="https://www.yoursite.com/purchase-history" /]

Remember, the ‘redirect’ parameter takes a URL as its value. This means you can use it to redirect the user to any page on your site, or even to an external site, after they have registered.

PHP Function Code

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

Shortcode line:

add_shortcode( 'edd_register', 'edd_register_form_shortcode' );

Shortcode PHP function:

function edd_register_form_shortcode( $atts, $content = null ) {
	$redirect         = home_url();
	$purchase_history = edd_get_option( 'purchase_history_page', 0 );

	if ( ! empty( $purchase_history ) ) {
		$redirect = get_permalink( $purchase_history );
	}

	extract( shortcode_atts( array(
		'redirect' => $redirect
	), $atts, 'edd_register' ) );

	return edd_register_form( $redirect );
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [download_discounts] Shortcode

The Easy Digital Downloads shortcode ‘download_discounts’ displays a list of active discounts. It checks if any discounts are available and active, then generates an HTML list. If active discounts exist, each is displayed with its name and formatted discount rate. If no discounts are found, a message is displayed.

Shortcode: [download_discounts]

Examples and Usage

Basic Example – A simple usage of the shortcode to display available discounts on your digital downloads.

[download_discounts]

PHP Function Code

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

Shortcode line:

add_shortcode( 'download_discounts', 'edd_discounts_shortcode' );

Shortcode PHP function:

function edd_discounts_shortcode( $atts, $content = null ) {
	$discounts = edd_get_discounts();

	$discounts_list = '<ul id="edd_discounts_list">';

	if ( ! empty( $discounts ) && edd_has_active_discounts() ) {

		foreach ( $discounts as $discount ) {

			if ( edd_is_discount_active( $discount->id ) ) {
				$discounts_list .= '<li class="edd_discount">';
					$discounts_list .= '<span class="edd_discount_name">' . edd_get_discount_code( $discount->id ) . '</span>';
					$discounts_list .= '<span class="edd_discount_separator"> - </span>';
					$discounts_list .= '<span class="edd_discount_amount">' . edd_format_discount_rate( edd_get_discount_type( $discount->id ), edd_get_discount_amount( $discount->id ) ) . '</span>';
				$discounts_list .= '</li>';
			}
		}

	} else {
		$discounts_list .= '<li class="edd_discount">' . __( 'No discounts found', 'easy-digital-downloads' ) . '</li>';
	}

	$discounts_list .= '</ul>';

	return $discounts_list;
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [purchase_collection] Shortcode

The Easy Digital Downloads shortcode ‘purchase_collection’ allows users to purchase all items in a specific taxonomy term. It creates a button with customizable text, style, and color.

Shortcode: [purchase_collection]

Parameters

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

  • taxonomy – Represents the classification of the product
  • terms – Specifies the terms related to the product
  • text – Defines the button text displayed to the user
  • style – Sets the visual style of the button
  • color – Determines the color scheme of the button
  • class – Assigns a CSS class to the button for further customization

Examples and Usage

Basic example – A simple usage of the shortcode to purchase a collection with a specified taxonomy and term. The button text is set as default.

[purchase_collection taxonomy="category" terms="ebooks" /]

Advanced examples

Modify the button text, style and color by using additional parameters. In this example, the taxonomy and terms are set to “genre” and “thriller”, respectively. The button text is customized to “Buy All Thriller Books”, and the style and color are set to “flat” and “blue”.

[purchase_collection taxonomy="genre" terms="thriller" text="Buy All Thriller Books" style="flat" color="blue" /]

Another advanced usage of the shortcode can be seen when the button class is modified. Here, the taxonomy and terms are set to “author” and “johndoe”, and the button class is customized to “my-custom-class”.

[purchase_collection taxonomy="author" terms="johndoe" class="my-custom-class" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'purchase_collection', 'edd_purchase_collection_shortcode' );

Shortcode PHP function:

function edd_purchase_collection_shortcode( $atts, $content = null ) {
	extract( shortcode_atts( array(
		'taxonomy' => '',
		'terms'    => '',
		'text'     => __( 'Purchase All Items', 'easy-digital-downloads' ),
		'style'    => edd_get_option( 'button_style', 'button' ),
		'color'    => edd_get_button_color_class(),
		'class'    => 'edd-submit',
	), $atts, 'purchase_collection' ) );

	$button_display = implode( ' ', array_filter( array( $style, $color, $class ) ) );

	return '<a href="' . esc_url( add_query_arg( array( 'edd_action' => 'purchase_collection', 'taxonomy' => sanitize_key( $taxonomy ), 'terms' => sanitize_key( $terms ) ) ) ) . '" class="' . esc_attr( $button_display ) . '">' . esc_html( $text ) . '</a>';
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [downloads] Shortcode

The Easy Digital Downloads shortcode is a powerful tool for displaying downloadable products. It allows customization of product listings based on categories, tags, authors, and more. It provides options to include/exclude categories or tags, specify the number of downloads to display, and control the display of price, excerpt, and buy button. It also supports pagination and custom CSS classes. The shortcode is flexible, allowing you to tailor your product display to meet your specific needs.

Shortcode: [downloads]

Parameters

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

  • category – to filter downloads by category
  • exclude_category – to exclude certain categories from the list
  • tags – to filter downloads by specific tags
  • exclude_tags – to exclude certain tags from the list
  • author – to show downloads by specific authors
  • relation – defines the relationship between taxonomy queries
  • number – sets the number of downloads to display
  • price – whether to display the price or not
  • excerpt – whether to display the excerpt or not
  • full_content – whether to display the full content or not
  • buy_button – whether to display the buy button or not
  • columns – number of columns to display the downloads in
  • thumbnails – whether to display thumbnails or not
  • orderby – set the order of downloads by parameters such as price, sales, earnings, title, ID or date
  • order – sets the direction of the order, either DESC (descending) or ASC (ascending)
  • ids – to display downloads by specific IDs
  • class – to add custom CSS classes to the downloads
  • pagination – whether to enable pagination or not

Examples and Usage

Basic example – In this example, we will use the shortcode to display a list of downloads without any specific parameters, so it will display the defaults set in the shortcode function.

[downloads /]

Advanced examples

Displaying downloads from a specific category. Here, the shortcode will display downloads from the category with the slug “ebooks”.

[downloads category="ebooks" /]

Displaying downloads excluding certain tags. In this example, the shortcode will display downloads excluding the tags with the slugs “free” and “discounted”.

[downloads exclude_tags="free,discounted" /]

Displaying downloads from a specific author. Here, the shortcode will display downloads from the author with the ID 1.

[downloads author="1" /]

Displaying a specific number of downloads. In this example, the shortcode will display 5 downloads.

[downloads number="5" /]

Displaying downloads with a specific order. Here, the shortcode will display downloads ordered by title in ascending order.

[downloads orderby="title" order="ASC" /]

Displaying downloads with specific IDs. In this example, the shortcode will display the downloads with the IDs 1, 2, and 3.

[downloads ids="1,2,3" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'downloads', 'edd_downloads_query' );

Shortcode PHP function:

function edd_downloads_query( $atts, $content = null ) {
	$atts = shortcode_atts( array(
		'category'         => '',
		'exclude_category' => '',
		'tags'             => '',
		'exclude_tags'     => '',
		'author'           => false,
		'relation'         => 'OR',
		'number'           => 9,
		'price'            => 'no',
		'excerpt'          => 'yes',
		'full_content'     => 'no',
		'buy_button'       => 'yes',
		'columns'          => 3,
		'thumbnails'       => 'true',
		'orderby'          => 'post_date',
		'order'            => 'DESC',
		'ids'              => '',
		'class'            => '',
		'pagination'       => 'true',
	), $atts, 'downloads' );

	$query = array(
		'post_type' => 'download',
		'orderby'   => $atts['orderby'],
		'order'     => $atts['order']
	);

	if ( filter_var( $atts['pagination'], FILTER_VALIDATE_BOOLEAN ) || ( ! filter_var( $atts['pagination'], FILTER_VALIDATE_BOOLEAN ) && $atts[ 'number' ] ) ) {

		$query['posts_per_page'] = (int) $atts['number'];

		if ( $query['posts_per_page'] < 0 ) {
			$query['posts_per_page'] = abs( $query['posts_per_page'] );
		}
	} else {
		$query['nopaging'] = true;
	}

	if( 'random' == $atts['orderby'] ) {
		$atts['pagination'] = false;
	}

	switch ( $atts['orderby'] ) {
		case 'price':
			$atts['orderby']   = 'meta_value';
			$query['meta_key'] = 'edd_price';
			$query['orderby']  = 'meta_value_num';
		break;

		case 'sales':
			$atts['orderby']   = 'meta_value';
			$query['meta_key'] = '_edd_download_sales';
			$query['orderby']  = 'meta_value_num';
		break;

		case 'earnings':
			$atts['orderby']   = 'meta_value';
			$query['meta_key'] = '_edd_download_earnings';
			$query['orderby']  = 'meta_value_num';
		break;

		case 'title':
			$query['orderby'] = 'title';
		break;

		case 'id':
			$query['orderby'] = 'ID';
		break;

		case 'random':
			$query['orderby'] = 'rand';
		break;

		case 'post__in':
			$query['orderby'] = 'post__in';
		break;

		default:
			$query['orderby'] = 'post_date';
		break;
	}

	if ( $atts['tags'] || $atts['category'] || $atts['exclude_category'] || $atts['exclude_tags'] ) {

		$query['tax_query'] = array(
			'relation' => $atts['relation']
		);

		if ( $atts['tags'] ) {

			$tag_list = explode( ',', $atts['tags'] );

			foreach( $tag_list as $tag ) {

				$t_id  = (int) $tag;
				$is_id = is_int( $t_id ) && ! empty( $t_id );

				if( $is_id ) {

					$term_id = $tag;

				} else {

					$term = get_term_by( 'slug', $tag, 'download_tag' );

					if( ! $term ) {
						continue;
					}

					$term_id = $term->term_id;
				}

				$query['tax_query'][] = array(
					'taxonomy' => 'download_tag',
					'field'    => 'term_id',
					'terms'    => $term_id
				);
			}

		}

		if ( $atts['category'] ) {

			$categories = explode( ',', $atts['category'] );

			foreach( $categories as $category ) {

				$t_id  = (int) $category;
				$is_id = is_int( $t_id ) && ! empty( $t_id );

				if( $is_id ) {

					$term_id = $category;

				} else {

					$term = get_term_by( 'slug', $category, 'download_category' );

					if( ! $term ) {
						continue;
					}

					$term_id = $term->term_id;

				}

				$query['tax_query'][] = array(
					'taxonomy' => 'download_category',
					'field'    => 'term_id',
					'terms'    => $term_id,
				);

			}

		}

		if ( $atts['exclude_category'] ) {

			$categories = explode( ',', $atts['exclude_category'] );

			foreach( $categories as $category ) {

				$t_id  = (int) $category;
				$is_id = is_int( $t_id ) && ! empty( $t_id );

				if( $is_id ) {

					$term_id = $category;

				} else {

					$term = get_term_by( 'slug', $category, 'download_category' );

					if( ! $term ) {
						continue;
					}

					$term_id = $term->term_id;
				}

				$query['tax_query'][] = array(
					'taxonomy' => 'download_category',
					'field'    => 'term_id',
					'terms'    => $term_id,
					'operator' => 'NOT IN'
				);
			}

		}

		if ( $atts['exclude_tags'] ) {

			$tag_list = explode( ',', $atts['exclude_tags'] );

			foreach( $tag_list as $tag ) {

				$t_id  = (int) $tag;
				$is_id = is_int( $t_id ) && ! empty( $t_id );

				if( $is_id ) {

					$term_id = $tag;

				} else {

					$term = get_term_by( 'slug', $tag, 'download_tag' );

					if( ! $term ) {
						continue;
					}

					$term_id = $term->term_id;
				}

				$query['tax_query'][] = array(
					'taxonomy' => 'download_tag',
					'field'    => 'term_id',
					'terms'    => $term_id,
					'operator' => 'NOT IN'
				);

			}

		}
	}

	if ( $atts['exclude_tags'] || $atts['exclude_category'] ) {
		$query['tax_query']['relation'] = 'AND';
	}

	if ( $atts['author'] ) {
		$authors = explode( ',', $atts['author'] );
		if ( ! empty( $authors ) ) {
			$author_ids = array();
			$author_names = array();

			foreach ( $authors as $author ) {
				if ( is_numeric( $author ) ) {
					$author_ids[] = $author;
				} else {
					$user = get_user_by( 'login', $author );
					if ( $user ) {
						$author_ids[] = $user->ID;
					}
				}
			}

			if ( ! empty( $author_ids ) ) {
				$author_ids      = array_unique( array_map( 'absint', $author_ids ) );
				$query['author'] = implode( ',', $author_ids );
			}
		}
	}

	if( ! empty( $atts['ids'] ) ) {
		$query['post__in'] = explode( ',', $atts['ids'] );
	}

	if ( get_query_var( 'paged' ) ) {
		$query['paged'] = get_query_var('paged');
	} else if ( get_query_var( 'page' ) ) {
		$query['paged'] = get_query_var( 'page' );
	} else {
		$query['paged'] = 1;
	}

	// Allow the query to be manipulated by other plugins
	$query = apply_filters( 'edd_downloads_query', $query, $atts );

	$downloads = new WP_Query( $query );

	do_action( 'edd_downloads_list_before', $atts );

	// Ensure buttons are not appended to content.
	remove_filter( 'the_content', 'edd_after_download_content' );

	ob_start();


	if ( $downloads->have_posts() ) :
		$i = 1;
		$columns_class   = array( 'edd_download_columns_' . $atts['columns'] );
		$custom_classes  = array_filter( explode( ',', $atts['class'] ) );
		$wrapper_classes = array_unique( array_merge( $columns_class, $custom_classes ) );
		$wrapper_classes = implode( ' ', $wrapper_classes );
	?>

		<div class="edd_downloads_list <?php echo apply_filters( 'edd_downloads_list_wrapper_class', $wrapper_classes, $atts ); ?>">

			<?php do_action( 'edd_downloads_list_top', $atts, $downloads ); ?>

			<?php while ( $downloads->have_posts() ) : $downloads->the_post(); ?>
				<?php do_action( 'edd_download_shortcode_item', $atts, $i ); ?>
			<?php $i++; endwhile; ?>

			<?php wp_reset_postdata(); ?>

			<?php do_action( 'edd_downloads_list_bottom', $atts ); ?>

		</div>

		<?php

	else :
		/* translators: plural download label */
		printf( _x( 'No %s found', 'download post type name', 'easy-digital-downloads' ), esc_html( edd_get_label_plural() ) );
	endif;

	do_action( 'edd_downloads_list_after', $atts, $downloads, $query );

	$display = ob_get_clean();

	// Ensure buttons are appended to content.
	add_filter( 'the_content', 'edd_after_download_content' );

	return apply_filters( 'downloads_shortcode', $display, $atts, $atts['buy_button'], $atts['columns'], '', $downloads, $atts['excerpt'], $atts['full_content'], $atts['price'], $atts['thumbnails'], $query );
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [edd_price] Shortcode

The ‘edd_price’ shortcode of the Easy Digital Downloads plugin retrieves the price of a digital download. The shortcode uses the ID of the download to fetch its price. The PHP code for the shortcode extracts the ID and price ID from the shortcode attributes. If no ID is given, it uses the ID of the current post. The code then calls the ‘edd_price’ function to return the download price.

Shortcode: [edd_price]

Parameters

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

  • id – The unique identifier for the digital download item.
  • price_id – Specific price variant for multi-price downloads.

Examples and Usage

Basic example – Showcases the usage of the ‘edd_price’ shortcode to display the price of a download with a specific ID.

[edd_price id=101 /]

Advanced examples

1. Demonstrates the usage of the ‘edd_price’ shortcode to display the price of a download with a specific ID and price ID. This is useful when the download has multiple pricing options.

[edd_price id=101 price_id=3 /]

2. Illustrates the use of the ‘edd_price’ shortcode without any explicit ID. In this case, the shortcode will automatically use the ID of the current post or page. This is convenient when the shortcode is used within a loop or a single download template.

[edd_price /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'edd_price', 'edd_download_price_shortcode' );

Shortcode PHP function:

function edd_download_price_shortcode( $atts, $content = null ) {
	extract( shortcode_atts( array(
		'id'       => null,
		'price_id' => false,
	), $atts, 'edd_price' ) );

	if ( is_null( $id ) ) {
		$id = get_the_ID();
	}

	return edd_price( $id, false, $price_id );
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [edd_receipt] Shortcode

The Easy Digital Downloads (EDD) shortcode, ‘edd_receipt’, generates a detailed receipt for customers after a purchase. It displays key information like price, discount, products, payment method, and more. It checks the payment key and returns an error message if it’s not found. If the user isn’t logged in, it prompts them to do so. The shortcode also ensures the user has permission to view the receipt.

Shortcode: [edd_receipt]

Parameters

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

  • error – message displayed when there’s an issue retrieving the order receipt.
  • price – controls whether or not the price is shown in the receipt.
  • discount – controls whether or not any applied discount is shown.
  • products – controls whether or not the purchased products are shown.
  • date – controls whether or not the purchase date is displayed.
  • notes – controls whether or not any notes are displayed.
  • payment_key – specific payment key, if provided, it will be used.
  • payment_method – controls whether or not the payment method is displayed.
  • payment_id – controls whether or not the payment ID is displayed.

Examples and Usage

Basic example – The basic usage of the ‘edd_receipt’ shortcode. This shortcode will display the receipt of the current user’s most recent purchase, provided the user is logged in and has made a purchase.

[edd_receipt /]

Advanced examples

Displaying the receipt with only the product details and the date of purchase. The ‘price’, ‘discount’, ‘notes’, ‘payment_key’, ‘payment_method’, and ‘payment_id’ parameters are set to ‘false’, so these details will not be shown on the receipt.

[edd_receipt price=false discount=false notes=false payment_key=false payment_method=false payment_id=false /]

Displaying the receipt with a custom error message. If there is a problem retrieving the receipt, this message will be displayed to the user.

[edd_receipt error="We encountered an issue while attempting to retrieve your receipt. Please try again later." /]

Displaying the receipt for a specific purchase. The ‘payment_key’ parameter is set to the unique key of the purchase. This will display the receipt for that specific purchase, regardless of who made the purchase or when it was made.

[edd_receipt payment_key="your_unique_payment_key" /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'edd_receipt', 'edd_receipt_shortcode' );

Shortcode PHP function:

function edd_receipt_shortcode( $atts, $content = null ) {
	global $edd_receipt_args;

	$edd_receipt_args = shortcode_atts( array(
		'error'          => __( 'Sorry, trouble retrieving order receipt.', 'easy-digital-downloads' ),
		'price'          => true,
		'discount'       => true,
		'products'       => true,
		'date'           => true,
		'notes'          => true,
		'payment_key'    => false,
		'payment_method' => true,
		'payment_id'     => true,
	), $atts, 'edd_receipt' );

	$session = edd_get_purchase_session();

	if ( isset( $_GET['payment_key'] ) ) {
		$payment_key = urldecode( $_GET['payment_key'] );
	} elseif ( ! empty( $_GET['order'] ) && ! empty( $_GET['id'] ) ) {
		$payment_key = edd_get_payment_key( absint( $_GET['id'] ) );
	} elseif ( $session ) {
		$payment_key = $session['purchase_key'];
	} elseif ( $edd_receipt_args['payment_key'] ) {
		$payment_key = $edd_receipt_args['payment_key'];
	}

	// No key found
	if ( ! isset( $payment_key ) ) {
		return '<p class="edd-alert edd-alert-error">' . $edd_receipt_args['error'] . '</p>';
	}

	$order         = edd_get_order_by( 'payment_key', $payment_key );
	$user_can_view = edd_can_view_receipt( $order );

	// Key was provided, but user is logged out. Offer them the ability to login and view the receipt
	if ( ! $user_can_view && ! empty( $payment_key ) && ! is_user_logged_in() && ! edd_is_guest_payment( $order ) ) {
		global $edd_login_redirect;
		$edd_login_redirect = edd_get_receipt_page_uri( $order->id );

		ob_start();

		echo '<p class="edd-alert edd-alert-warn">' . __( 'You must be logged in to view this payment receipt.', 'easy-digital-downloads' ) . '</p>';
		edd_get_template_part( 'shortcode', 'login' );

		$login_form = ob_get_clean();

		return $login_form;
	}

	$user_can_view = apply_filters( 'edd_user_can_view_receipt', $user_can_view, $edd_receipt_args );

	// If this was a guest checkout and the purchase session is empty, output a relevant error message
	if ( empty( $session ) && ! is_user_logged_in() && ! $user_can_view ) {
		return '<p class="edd-alert edd-alert-error">' . apply_filters( 'edd_receipt_guest_error_message', __( 'Receipt could not be retrieved, your purchase session has expired.', 'easy-digital-downloads' ) ) . '</p>';
	}

	/*
	 * Check if the user has permission to view the receipt
	 *
	 * If user is logged in, user ID is compared to user ID of ID stored in payment meta
	 *
	 * Or if user is logged out and purchase was made as a guest, the purchase session is checked for
	 *
	 * Or if user is logged in and the user can view sensitive shop data
	 */

	if ( ! $user_can_view ) {
		return '<p class="edd-alert edd-alert-error">' . $edd_receipt_args['error'] . '</p>';
	}

	ob_start();

	edd_get_template_part( 'shortcode', 'receipt' );

	$display = ob_get_clean();

	return $display;
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Easy Digital Downloads [edd_profile_editor] Shortcode

The Easy Digital Downloads (EDD) shortcode, ‘edd_profile_editor’, allows users to edit their profiles directly from the frontend. It checks if the user’s account is verified. If not, it displays a ‘pending’ message.

Shortcode: [edd_profile_editor]

Examples and Usage

Basic example – Displays the user’s profile editor or a verification pending message, depending on the user’s verification status.

[edd_profile_editor /]

PHP Function Code

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

Shortcode line:

add_shortcode( 'edd_profile_editor', 'edd_profile_editor_shortcode' );

Shortcode PHP function:

function edd_profile_editor_shortcode( $atts = null, $content = null ) {
	ob_start();

	if ( ! edd_user_pending_verification() ) {
		edd_get_template_part( 'shortcode', 'profile-editor' );
	} else {
		edd_get_template_part( 'account', 'pending' );
	}

	$display = ob_get_clean();

	return $display;
}

Code file location:

easy-digital-downloads/easy-digital-downloads/includes/shortcodes.php

Conclusion

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