Functions – Easy Digital Downloads Documentation https://easydigitaldownloads.com Sell Digital Products With WordPress Mon, 02 Dec 2024 14:23:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://easydigitaldownloads.com/wp-content/uploads/2023/10/cropped-new-favicon-1-32x32.png Functions – Easy Digital Downloads Documentation https://easydigitaldownloads.com 32 32 edd_debug_log https://easydigitaldownloads.com/docs/edd-debug-log/ Fri, 14 Jul 2023 17:26:14 +0000 https://easydigitaldownloads.com/?post_type=edd_doc&p=1794467 When debug mode is enabled (Downloads > Settings > Misc > General), specific information will be logged to a custom log file on your site. Developers can make use of this to help troubleshoot issues and results at specific points in their code.

The post edd_debug_log first appeared on Easy Digital Downloads.

]]>
When debug mode is enabled (Downloads > Settings > Misc > General), specific information will be logged to a custom log file on your site. Developers can make use of this to help troubleshoot issues and results at specific points in their code.

edd_debug_log( $message = '', $force = false );
  • $message: This must be a string, and it’s exactly what will show in the log file.
  • $force: Use the function with this parameter set to true to force your message to be added to the log file, even if debug mode is not enabled. Use this only for critical messages and warnings.

The post edd_debug_log first appeared on Easy Digital Downloads.

]]>
edd_get_download_earnings_stats() https://easydigitaldownloads.com/docs/edd_get_download_earnings_stats/ Mon, 24 Jan 2022 19:58:33 +0000 https://edd-site.lndo.site/docs/edd_get_download_earnings_stats/ This function will retrieve the total amount a particular download has earned in sales. $earnings = edd_get_download_earnings_stats( $download_id );

The post edd_get_download_earnings_stats() first appeared on Easy Digital Downloads.

]]>
This function will retrieve the total amount a particular download has earned in sales.

$earnings = edd_get_download_earnings_stats( $download_id );

The post edd_get_download_earnings_stats() first appeared on Easy Digital Downloads.

]]>
edd_has_variable_prices() https://easydigitaldownloads.com/docs/edd_has_variable_prices/ Mon, 24 Jan 2022 19:58:29 +0000 https://edd-site.lndo.site/docs/edd_has_variable_prices/ This function will check whether a download has variable prices enabled. If the specified ID has variable prices, the function will return true, otherwise it will return false. Example: if( edd_has_variable_prices( $download_id ) ) { // download has variable prices enabled } else { // variable prices are not enabled }

The post edd_has_variable_prices() first appeared on Easy Digital Downloads.

]]>
This function will check whether a download has variable prices enabled. If the specified ID has variable prices, the function will return true, otherwise it will return false.

Example:

if( edd_has_variable_prices( $download_id ) ) {
	// download has variable prices enabled
} else {
	// variable prices are not enabled
}

The post edd_has_variable_prices() first appeared on Easy Digital Downloads.

]]>
edd_is_ajax_enabled() https://easydigitaldownloads.com/docs/edd_is_ajax_enabled/ Mon, 24 Jan 2022 19:58:24 +0000 https://edd-site.lndo.site/docs/edd_is_ajax_enabled/ This function can be used to check if ajax is enabled for Easy Digital Downloads. If you are integrating EDD into your theme, this may be very useful. $is_ajaxed = edd_is_ajax_enabled(); // (boolean) "false" if not enabled // (boolean) "true" if is enabled

The post edd_is_ajax_enabled() first appeared on Easy Digital Downloads.

]]>
This function can be used to check if ajax is enabled for Easy Digital Downloads. If you are integrating EDD into your theme, this may be very useful.

$is_ajaxed = edd_is_ajax_enabled();
// (boolean) "false" if not enabled
// (boolean) "true" if is enabled

The post edd_is_ajax_enabled() first appeared on Easy Digital Downloads.

]]>
edd_get_price_option_name() https://easydigitaldownloads.com/docs/edd_get_price_option_name/ Mon, 24 Jan 2022 19:58:19 +0000 https://edd-site.lndo.site/docs/edd_get_price_option_name/ This function can be used for getting the name of a specified price from a specific download. $price_name = edd_get_price_option_name( $download_id, $price_id ); // $price_name will be something like "Regular License"

The post edd_get_price_option_name() first appeared on Easy Digital Downloads.

]]>
This function can be used for getting the name of a specified price from a specific download.

$price_name = edd_get_price_option_name( $download_id, $price_id );
// $price_name will be something like "Regular License"

The post edd_get_price_option_name() first appeared on Easy Digital Downloads.

]]>
edd_get_download_sales_stats() https://easydigitaldownloads.com/docs/edd_get_download_sales_stats/ Mon, 24 Jan 2022 19:58:14 +0000 https://edd-site.lndo.site/docs/edd_get_download_sales_stats/ This function will retrieve the total number of sales for a particular download. $sales = edd_get_download_sales_stats( $download_id );

The post edd_get_download_sales_stats() first appeared on Easy Digital Downloads.

]]>
This function will retrieve the total number of sales for a particular download.

$sales = edd_get_download_sales_stats( $download_id );

The post edd_get_download_sales_stats() first appeared on Easy Digital Downloads.

]]>
edd_is_test_mode() https://easydigitaldownloads.com/docs/edd_is_test_mode/ Mon, 24 Jan 2022 19:58:10 +0000 https://edd-site.lndo.site/docs/edd_is_test_mode/ This function can be used to check if test mode is enabled for Easy Digital Downloads. $test_mode = edd_is_test_mode(); // (boolean) "false" if not enabled // (boolean) "true" if is enabled

The post edd_is_test_mode() first appeared on Easy Digital Downloads.

]]>
This function can be used to check if test mode is enabled for Easy Digital Downloads.

$test_mode = edd_is_test_mode();
// (boolean) "false" if not enabled
// (boolean) "true" if is enabled

The post edd_is_test_mode() first appeared on Easy Digital Downloads.

]]>
edd_update_option https://easydigitaldownloads.com/docs/edd_update_option/ Mon, 24 Jan 2022 19:58:08 +0000 https://edd-site.lndo.site/docs/edd_update_option/ Options specific to Easy Digital Downloads are stored in an array in a single WordPress option. For this reason it’s best to use edd_update_option() to change those options. edd_update_option() safely filters and updates an existing option. Input edd_update_option() takes two input variables. The first is the key name of the option desired.  The second is

The post edd_update_option first appeared on Easy Digital Downloads.

]]>
Options specific to Easy Digital Downloads are stored in an array in a single WordPress option. For this reason it’s best to use
edd_update_option() to change those options. edd_update_option() safely filters and updates an existing option.

Input

edd_update_option() takes two input variables. The first is the key name of the option desired.  The second is the value that should be stored in the option. The second value defaults to false. Example:

edd_update_option( $key = '', $value = false )

Usage

Here’s an example, updating the position of the currency indicator.  By default it’s set to ‘before’, this example will set it to ‘after’.

edd_update_option( 'currency_position', 'after' );

Output

This function returns true if the option is updated, otherwise false.

The post edd_update_option first appeared on Easy Digital Downloads.

]]>
edd_add_email_tag() https://easydigitaldownloads.com/docs/edd_add_email_tag/ Mon, 24 Jan 2022 19:57:57 +0000 https://edd-site.lndo.site/docs/edd_add_email_tag/ The edd_add_email_tag() function allows you to register custom email tags for purchase receipts and admin sale notifications and takes three parameters: Here’s an example snippet that you can use and extend as needed: https://library.wpcode.com/snippet/j578kp2g/

The post edd_add_email_tag() first appeared on Easy Digital Downloads.

]]>
The edd_add_email_tag() function allows you to register custom email tags for purchase receipts and admin sale notifications and takes three parameters:

  • $tag – The tag to register, such as “admin_email”. In the email settings, tags are wrapped with {} but not when they are registered.
  • $description – A description of what the tag displays.
  • $func – The call back function to render the tag’s output.

Here’s an example snippet that you can use and extend as needed: https://library.wpcode.com/snippet/j578kp2g/

The post edd_add_email_tag() first appeared on Easy Digital Downloads.

]]>
edd_email_purchase_receipt() https://easydigitaldownloads.com/docs/edd_email_purchase_receipt/ Mon, 24 Jan 2022 19:57:56 +0000 https://edd-site.lndo.site/docs/edd_email_purchase_receipt/ This function can be used for resending the email purchase receipt for any purchase. If you ever want to resend the purchase receipt, but need to use your own methods (instead of the built-in option in Downloads > Payment History), you can simply trigger this function: edd_email_purchase_receipt( $payment_id, false ); The first parameter if the

The post edd_email_purchase_receipt() first appeared on Easy Digital Downloads.

]]>
This function can be used for resending the email purchase receipt for any purchase.

If you ever want to resend the purchase receipt, but need to use your own methods (instead of the built-in option in Downloads > Payment History), you can simply trigger this function:

edd_email_purchase_receipt( $payment_id, false );

The first parameter if the ID of the purchase to resend the email for, and the second parameter is whether or not to send a notice to the admin as well (probably should leave this as false.

The post edd_email_purchase_receipt() first appeared on Easy Digital Downloads.

]]>
edd_set_payment_transaction_id() https://easydigitaldownloads.com/docs/edd_set_payment_transaction_id/ Mon, 24 Jan 2022 19:57:53 +0000 https://edd-site.lndo.site/docs/edd_set_payment_transaction_id/ The  edd_set_payment_transaction_id() function is used to set the transaction ID related to a specific purchase. The function takes two parameters, one for the payment ID and one for the transaction ID: edd_set_payment_transaction_id( $payment_id, $transaction_id ); The transaction ID is passed through a filter called  edd_set_payment_transaction_id, which receives two parameters: $transaction_id $payment_id Transaction ID tracking was implemented in EDD v2.1.

The post edd_set_payment_transaction_id() first appeared on Easy Digital Downloads.

]]>
The 
edd_set_payment_transaction_id() function is used to set the transaction ID related to a specific purchase.

The function takes two parameters, one for the payment ID and one for the transaction ID:

edd_set_payment_transaction_id( $payment_id, $transaction_id );

The transaction ID is passed through a filter called 
edd_set_payment_transaction_id, which receives two parameters:

  • $transaction_id
  • $payment_id

Transaction ID tracking was implemented in EDD v2.1.

The post edd_set_payment_transaction_id() first appeared on Easy Digital Downloads.

]]>
edd_format_amount() https://easydigitaldownloads.com/docs/edd_format_amount/ Mon, 24 Jan 2022 19:57:47 +0000 https://edd-site.lndo.site/docs/edd_format_amount/ This function can be used for format a given price. It will return the result formatted to the correct number of decimals. echo edd_format_amount( 9.5 ); You could combine it with edd_get_download_price() to return the formatted price for any download: echo edd_format_amount( edd_get_download_price( $download_id ) ); If you wish to include a currency symbol you

The post edd_format_amount() first appeared on Easy Digital Downloads.

]]>
This function can be used for format a given price. It will return the result formatted to the correct number of decimals.

echo edd_format_amount( 9.5 );

You could combine it with edd_get_download_price() to return the formatted price for any download:

echo edd_format_amount( edd_get_download_price( $download_id ) );

If you wish to include a currency symbol you can filter the output with edd_currency_filter.

echo edd_currency_filter( edd_format_amount( edd_get_download_price( $download_id ) ) );

The post edd_format_amount() first appeared on Easy Digital Downloads.

]]>
edd_get_variable_prices() https://easydigitaldownloads.com/docs/edd_get_variable_prices/ Mon, 24 Jan 2022 19:57:44 +0000 https://edd-site.lndo.site/docs/edd_get_variable_prices/ This function will return an array of all of the variable prices set for the provided download ID. $prices = edd_get_variable_prices( $download_id ); if( $prices ) { foreach( $prices as $price_id => $price ) { // $price['name'] is the name of the price // $price['amount'] is the amount of the price } }

The post edd_get_variable_prices() first appeared on Easy Digital Downloads.

]]>
This function will return an array of all of the variable prices set for the provided download ID.

$prices = edd_get_variable_prices( $download_id );
if( $prices ) {
	foreach( $prices as $price_id => $price ) {
		// $price['name'] is the name of the price
		// $price['amount'] is the amount of the price
	}
}

The post edd_get_variable_prices() first appeared on Easy Digital Downloads.

]]>
edd_get_option https://easydigitaldownloads.com/docs/edd_get_option/ Mon, 24 Jan 2022 19:57:40 +0000 https://edd-site.lndo.site/docs/edd_get_option/ Options specific to Easy Digital Downloads are stored in an array in a single WordPress option. For this reason it’s best to use edd_get_option() to get those options. edd_get_option() safely finds the desired option and returns it.  Additionally, it applies a filter to the output. Input edd_get_option() takes two input variables. The first is the

The post edd_get_option first appeared on Easy Digital Downloads.

]]>
Options specific to Easy Digital Downloads are stored in an array in a single WordPress option. For this reason it’s best to use
edd_get_option() to get those options. edd_get_option() safely finds the desired option and returns it.  Additionally, it applies a filter to the output.

Input

edd_get_option() takes two input variables. The first is the key name of the option desired.  The second is a default value if the key is not found in the option array. The second value defaults to false.

Usage

Here’s an example, looking for the position of the currency indicator.  If it’s not found, $position will get a value of ‘before’.

$position = edd_get_option( 'currency_position', 'before' );

Output

The output of this function will be whatever was stored in the option, OR the default. The return function applies a filter that looks like this:

return apply_filters( 'edd_get_option_' . $key, $value, $key, $default );

Using the example from the Usage section then the filter would be named
edd_get_option_currency_position.

The post edd_get_option first appeared on Easy Digital Downloads.

]]>
edd_get_download_files() https://easydigitaldownloads.com/docs/edd_get_download_files/ Mon, 24 Jan 2022 19:57:30 +0000 https://edd-site.lndo.site/docs/edd_get_download_files/ This function can be used for retrieving all downloadable files attached to a download product. $files = edd_get_download_files( $download_id, $variable_price_id = null ); if( $files ) { foreach( $files as $filekey => $file ) { // Name: $file['name'] // URL or path: $file['file'] } } The first parameter is the ID of the download product

The post edd_get_download_files() first appeared on Easy Digital Downloads.

]]>
This function can be used for retrieving all downloadable files attached to a download product.

$files = edd_get_download_files( $download_id, $variable_price_id = null );
if( $files ) {
	foreach( $files as $filekey => $file ) {
		// Name: $file['name']
		// URL or path: $file['file']
	}
}

The first parameter is the ID of the download product you want to retrieve files for, and the second parameter is an option price ID. If your download has variable prices enabled, you can pass the ID of a price and only the files available to that price ID will be returned.

The post edd_get_download_files() first appeared on Easy Digital Downloads.

]]>
edd_get_payment_transaction_id() https://easydigitaldownloads.com/docs/edd_get_payment_transaction_id/ Mon, 24 Jan 2022 19:57:22 +0000 https://edd-site.lndo.site/docs/edd_get_payment_transaction_id/ The  edd_get_payment_transaction_id() function is used to retrieve the transaction ID related to a specific purchase. The function takes the payment ID as a parameter: $trans_id = edd_get_payment_transaction_id( $payment_id ); The transaction ID returned is passed through a filter called  edd_get_payment_transaction_id, which receives two parameters: $transaction_id $payment_id Transaction ID tracking was implemented in EDD v2.1 and is

The post edd_get_payment_transaction_id() first appeared on Easy Digital Downloads.

]]>
The 
edd_get_payment_transaction_id() function is used to retrieve the transaction ID related to a specific purchase.

The function takes the payment ID as a parameter:

$trans_id = edd_get_payment_transaction_id( $payment_id );

The transaction ID returned is passed through a filter called 
edd_get_payment_transaction_id, which receives two parameters:

  • $transaction_id
  • $payment_id

Transaction ID tracking was implemented in EDD v2.1 and is done on a per-gateway basis, so not all payment records will have transaction IDs. If a transaction ID does not exist for a payment record, the 
edd_get_payment_transaction_id-{gateway name} filter is applied before the edd_get_payment_transaction_id filter so that the transaction ID can (possibly) be pulled from the payment notes. This allows payment gateways to update old payment records over time by retrieving the transaction ID from a custom storage method unique to that gateway.

The post edd_get_payment_transaction_id() first appeared on Easy Digital Downloads.

]]>
edd_has_user_purchased() https://easydigitaldownloads.com/docs/edd_has_user_purchased/ Mon, 24 Jan 2022 19:57:17 +0000 https://edd-site.lndo.site/docs/edd_has_user_purchased/ This conditional function will allow you to check whether a user has purchased a particular digital product. The function takes two parameters: $user_id – the ID number of the user to check $download_id – the ID number of the download to check Example: if( edd_has_user_purchased($user_id, $download_id) ) { // the current user HAS purchased $download_id

The post edd_has_user_purchased() first appeared on Easy Digital Downloads.

]]>
This conditional function will allow you to check whether a user has purchased a particular digital product.

The function takes two parameters:

  • $user_id – the ID number of the user to check
  • $download_id – the ID number of the download to check

Example:

if( edd_has_user_purchased($user_id, $download_id) ) {
	// the current user HAS purchased $download_id
} else {
	// the current user has NOT purchase $download_id	
}

The post edd_has_user_purchased() first appeared on Easy Digital Downloads.

]]>
edd_get_download() https://easydigitaldownloads.com/docs/edd_get_download/ Mon, 24 Jan 2022 19:57:13 +0000 https://edd-site.lndo.site/docs/edd_get_download/ This function can be used to retrieve the post object for a download by either ID or slug. Example: $download = edd_get_download(34); // retrieve the download post data for ID 34 $download = edd_get_download('my-awesome-download'); // retrieve the download post data for slug "my-awesome-download" // you can now do things like this: $title = $download->post_title;

The post edd_get_download() first appeared on Easy Digital Downloads.

]]>
This function can be used to retrieve the post object for a download by either ID or slug.

Example:

$download = edd_get_download(34); // retrieve the download post data for ID 34 
$download = edd_get_download('my-awesome-download'); // retrieve the download post data for slug "my-awesome-download"
// you can now do things like this:
$title = $download->post_title;

The post edd_get_download() first appeared on Easy Digital Downloads.

]]>
edd_get_cart_contents() https://easydigitaldownloads.com/docs/edd_get_cart_contents/ Mon, 24 Jan 2022 19:57:07 +0000 https://edd-site.lndo.site/docs/edd_get_cart_contents/ This function returns a nested array of items currently in the cart. Each item, by default, contains the following items: id – The download ID of the cart item options – An array holding optional data, such as price_id (when variable pricing is enabled for the download) quantity – The quantity value. When quantities are

The post edd_get_cart_contents() first appeared on Easy Digital Downloads.

]]>
This function returns a nested array of items currently in the cart. Each item, by default, contains the following items:

  • id – The download ID of the cart item
  • options – An array holding optional data, such as price_id (when variable pricing is enabled for the download)
  • quantity – The quantity value. When quantities are disabled, this should always read 1

Common uses of the options array are things like variable pricing, software licensing upgrades & renewals, and recurring payments.

Example Usage

$cart_contents = edd_get_cart_contents();
if ( ! empty( $cart_contents ) ) {
	foreach ( $cart_contents as $item ) {
		// Execute your code
	}
}

Note: In our example we assigned the contents of edd_get_cart_contents() to a variable before checking it with the `empty` function in our conditional statement. This is to maintain compatibility with PHP 5.2.

Important Information

When called, this function does validate that each item in the cart meets two requirements.

  1. That it is of the post type `download`.
  2. That the item is in a status that allows it to be purchased (non-editors cannot purchase posts that are not published).

If an item fails to meet either of those two requirements, it will be removed from the cart prior to returning the results.

Filters

This function contains one filter just before returning its results. The filter name is:

return apply_filters( 'edd_cart_contents', $cart );

It passes in one argument, which is the current cart contents, after all validation has been done.

Find this function in GitHub

The post edd_get_cart_contents() first appeared on Easy Digital Downloads.

]]>
edd_price() https://easydigitaldownloads.com/docs/edd_price/ Mon, 24 Jan 2022 19:57:06 +0000 https://edd-site.lndo.site/docs/edd_price/ This function will output a nicely formatted price of any specified download. It accepts three parameters: A download id, for the download whose price should be displayed An echo boolean. Defaults to true. A price id for variable pricing. Defaults to the first variation Example: edd_price( 12 ); // will output something like $10 for

The post edd_price() first appeared on Easy Digital Downloads.

]]>
This function will output a nicely formatted price of any specified download. It accepts three parameters:

  • A download id, for the download whose price should be displayed
  • An echo boolean. Defaults to true.
  • A price id for variable pricing. Defaults to the first variation

Example:

edd_price( 12 ); // will output something like $10 for product 12

$edd_price = edd_price( 12, false ); // stores the amount for download id 12 in $edd_price

edd_price( 12, true, 1 ); // echos the price of the first variation on download id 12

The price amount is formatted with the currency set in the plugin options, as well as the currency sign position.

For an example of using this in a theme,
see here.

The post edd_price() first appeared on Easy Digital Downloads.

]]>