Classes – Easy Digital Downloads Documentation https://easydigitaldownloads.com Sell Digital Products With WordPress Mon, 19 May 2025 19:44:07 +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 Classes – Easy Digital Downloads Documentation https://easydigitaldownloads.com 32 32 EDD Export Class https://easydigitaldownloads.com/docs/edd_export-class/ Mon, 24 Jan 2022 19:58:39 +0000 https://edd-site.lndo.site/docs/edd_export-class/ Overview The Easy Digital Downloads Export system provides a robust framework for creating custom data exports. This documentation covers the base Exporter class and how to implement custom exporters. Requirements Base Export Class The Exporter class is located in the EDD\Admin\Exports\Exporters namespace and serves as the foundation for all EDD export functionality. Required Methods When

The post EDD Export Class first appeared on Easy Digital Downloads.

]]>
Overview

The Easy Digital Downloads Export system provides a robust framework for creating custom data exports. This documentation covers the base Exporter class and how to implement custom exporters.

Requirements

  • WordPress 6.2+
  • Easy Digital Downloads 3.3.8+
  • PHP 7.4+

Base Export Class

The Exporter class is located in the EDD\Admin\Exports\Exporters namespace and serves as the foundation for all EDD export functionality.

Required Methods

When extending the Exporter class, you must implement these abstract methods:

abstract protected function get_export_type(): string;
abstract protected function get_data(): array;
abstract protected function get_data_headers(): array;
abstract protected function get_total(): int;
abstract public function set_properties( $request ): void;

Creating a Custom Exporter

1. Basic Structure

Create a class that extends the Exporter class:

<?php

/**
 * Custom Exporter class.
 */
class CustomExporter extends EDD\Admin\Exports\Exporters\Exporter {

	/**
	 * Get the export type.
	 *
	 * @return string The export type.
	 */
	protected function get_export_type(): string {
		return 'custom_export';
	}

	/**
	 * Set the properties.
	 *
	 * @param array $request The request.
	 * @return void
	 */
	public function set_properties( $request ): void {
		$this->start = isset( $request['custom-export-start'] )
			? sanitize_text_field( $request['custom-export-start'] )
			: '';
		$this->end   = isset( $request['custom-export-end'] )
			? sanitize_text_field( $request['custom-export-end'] )
			: '';
	}

	/**
	 * Get the data headers.
	 *
	 * @return array The data headers.
	 */
	protected function get_data_headers(): array {
		return array(
			'id'     => __( 'ID', 'your-text-domain' ),
			'status' => __( 'Status', 'your-text-domain' ),
		);
	}

	protected function get_data(): array {
		$data = array();
		$args = array_merge(
			array(
				'number' => $this->per_step,
				'offset' => ( $this->step * $this->per_step ) - $this->per_step,
			),
			$this->get_base_args()
		);

		// Your data retrieval logic here
		$items = edd_get_orders( $args );

		foreach ( $items as $item ) {
			$data[] = array(
				'id'     => $item->id,
				'status' => $item->status,
			);
		}

		return $data;
	}

	/**
	 * Get the total.
	 *
	 * @return int The total.
	 */
	protected function get_total(): int {
		return edd_count_orders( $this->get_base_args() );
	}

	/**
	 * Get the base args.
	 *
	 * @return array The base args.
	 */
	private function get_base_args(): array {
		$args = array();
		if ( ! empty( $this->start ) || ! empty( $this->end ) ) {
			$args['date_query'] = $this->get_date_query();
		}
		return $args;
	}
}

2. Registering Your Exporter

Create a class to handle the registration and form display:

/**
 * Register the custom exporter.
 *
 * @param \EDD\Admin\Exports\Registry $registry The registry instance.
 * @return void
 */
function custom_register_export( \EDD\Admin\Exports\Registry $registry ) {
	$registry->register_exporter(
		'custom_export',
		array(
			'label'       => __( 'Custom Export', 'your-text-domain' ),
			'description' => __( 'Export custom data.', 'your-text-domain' ),
			'class'       => CustomExporter::class,
			'class_path'  => __DIR__ . '/class-custom-export.php', // Change to your export class path.
			'button'      => __( 'Export Data', 'your-text-domain' ),
		)
	);
}
add_action( 'edd_export_init', 'custom_register_export' );

/**
 * Display the custom export form.
 *
 * @param string $exporter_id The exporter ID.
 * @return void
 */
function custom_export_form( $exporter_id ) {
	if ( 'custom_export' !== $exporter_id ) {
		return;
	}

	$from_to = new \EDD\HTML\FromTo(
		array(
			'legend' => __( 'Custom Export Date', 'your-text-domain' ),
			'id'     => 'order-export',
		)
	);
	$from_to->output();
	?>
		<label for="edd_export_custom_status" class="screen-reader-text"><?php esc_html_e( 'Select Status', 'your-text-domain' ); ?></label>
		<?php
		$statuses = array();
		foreach ( edd_get_payment_statuses() as $status ) {
			if ( 'publish' === $status ) {
				continue;
			}
			$statuses[ $status ] = edd_get_payment_status_label( $status );
		}
		$select = new \EDD\HTML\Select(
			array(
				'id'               => 'edd_export_custom_status',
				'name'             => 'status',
				'show_option_all'  => __( 'All Statuses', 'your-text-domain' ),
				'show_option_none' => false,
				'selected'         => false,
				'options'          => $statuses,
			)
		);
		$select->output();
}
add_action( 'edd_export_form', 'custom_export_form' );

With the new export registry, once you have your export class set up along with your form, EDD will handle the export process automatically.

Sources:

The post EDD Export Class first appeared on Easy Digital Downloads.

]]>
EDD_Graph https://easydigitaldownloads.com/docs/edd_graph/ Mon, 24 Jan 2022 19:58:38 +0000 https://edd-site.lndo.site/docs/edd_graph/ The EDD_Graph class, introduced in EDD version 1.9, is used for easily building graphs of data. For example, the earnings / sales reports graphs seen in Downloads → Reports are created using EDD_Graph. The class can be used by extensions to quickly graph any data set. A simple example looks like this: $data = array(

The post EDD_Graph first appeared on Easy Digital Downloads.

]]>
The EDD_Graph class, introduced in EDD version 1.9, is used for easily building graphs of data. For example, the earnings / sales reports graphs seen in Downloads → Reports are created using EDD_Graph. The class can be used by extensions to quickly graph any data set.


A simple example looks like this:

$data = array(
	'Your Graph Label Here' => array(
		array( 1, 5 ),
		array( 3, 8 ),
		array( 10, 2 )
	),
	'Second Label Here' => array(
		array( 1, 7 ),
		array( 4, 5 ),
		array( 12, 8 )
	)
);
$graph = new EDD_Graph( $data );
$graph->display();

Each inner array represents a data point on the graph and should be structured like this:

array( 'value on x axis', 'value on y axis' )

Graphs can contain one one or more lines. To add multiple lines, simply add additional inner arrays, as shown in the example above.

Along with the data points, EDD_Grap allows you to control various options of the graph by using the set() method. For example:

// Example with options set to other than default:
$data = array(
    'Line Label' => array(
        array( 1, 5 ),
        array( 3, 8 ),
        array( 10, 2 )
    ),
    'Second Line Label' => array(
        array( 1, 7 ),
        array( 4, 5 ),
        array( 12, 8 )
    )
);
$graph = new EDD_Graph( $data );
$graph->set( 'bgcolor', '#000' );
$graph->set( 'color', '#fff' );
$graph->display();

The available options are:

  • y_mode
  • x_mode
  • y_decimals
  • x_decimals
  • y_position
  • time_format
  • ticksize_unit
  • ticksize_num
  • multiple_y_axes
  • bgcolor
  • bordercolor
  • color
  • borderwidth
  • bars
  • lines
  • points

See the Flot API reference for the possible values each of these can receive.

Note, if you want to display a graph on the front end, you will need to include includes/admin/reporting/class-edd-graph.php first.

The post EDD_Graph first appeared on Easy Digital Downloads.

]]>
EDD_Payment_Stats https://easydigitaldownloads.com/docs/edd_payment_stats/ Mon, 24 Jan 2022 19:58:13 +0000 https://edd-site.lndo.site/docs/edd_payment_stats/ The  EDD_Payment_Stats class is designed to provide a simple way to retrieve earnings and sales stats for the entire store, or specific products, for designated time periods, such as this week, last month, today, last year, etc. To use  EDD_Payment_Stats, you must instantiate a new instance of the class: $stats = new EDD_Payment_Stats; Once the

The post EDD_Payment_Stats first appeared on Easy Digital Downloads.

]]>
The 
EDD_Payment_Stats class is designed to provide a simple way to retrieve earnings and sales stats for the entire store, or specific products, for designated time periods, such as this week, last month, today, last year, etc.

To use 
EDD_Payment_Stats, you must instantiate a new instance of the class:

$stats = new EDD_Payment_Stats;

Once the class is instantiated, you can use any of the following member functions:

// Retrieve earnings
$stats->get_earnings( $download_id = 0, $start_date = false, $end_date = false );
// Retrieve sales
$stats->get_sales( $download_id = 0, $start_date = false, $end_date = false );
// Retrieve a list of the best selling Download products
$stats->get_best_selling( $number = 10 );

For both 
get_sales() and get_earnings(), the following parameters can be passed:

$download_id – The ID number of the product to retrieve stats for. If 0 or any other empty value is passed, stats will be retrieved for the whole store.

$start_date – The beginning date to retrieve stats for. If you want to retrieve stats for one of the pre-defined periods, simply pass the period, such as “today” or “yesterday”. This parameter can be a date string, a timestamp, or a date formatted in any standard format.

$end_date – The end date to retrieve stats for. If you want to retrieve stats for one of the pre-defined periods, leave this blank. This parameter can be a date string, a timestamp, or a date formatted in any standard format.

Stats can be retrieved for any pre-defined time period. These options include:

  • today
  • yesterday
  • this_week
  • last_week
  • this_month
  • last_month
  • this_quarter
  • last_quarter
  • this_year
  • last_year

Examples

// Store-wide sales for this month:
echo $stats->get_sales( 0, 'this_month' );

Returns an integer, the sum of sales in the given time span
// Store-wide earnings for August 2, 2013
echo $stats->get_earnings( 0, 'August 2, 2013' );

Returns an integer if earnings are a whole number, a float rounded to 2 if a 
fractional number, like 42.73
// Sales for download ID 44 from July 2 to August 5, 2013
echo $stats->get_sales( 44, 'July 2, 2013', 'August 5, 2013' );
// Earnings for download ID 52 for December 5, 2012
echo $stats->get_earnings( 52, '12-05-2012' )
$best_selling = $stats->get_best_selling( '10' );

Returns an array of the 10 best selling products, like this:

Array
(
    [0] => stdClass Object
        (
            [download_id] => 68
            [sales] => 3
        )

    [1] => stdClass Object
        (
            [download_id] => 120
            [sales] => 2
        )
)

The post EDD_Payment_Stats first appeared on Easy Digital Downloads.

]]>
EDD_Emails https://easydigitaldownloads.com/docs/edd_emails/ Mon, 24 Jan 2022 19:57:52 +0000 https://edd-site.lndo.site/docs/edd_emails/ Introduced in Easy Digital Downloads version 2.1, the EDD_Emails class handles the construction and sending of purchase receipts and admin sale notifications. It is also used by extensions to send custom emails in the standard HTML template. To send an email using the EDD_Emails, class, call the send() method from the main EDD() instance, like this: EDD()->emails->send( $to, $subject, $message

The post EDD_Emails first appeared on Easy Digital Downloads.

]]>
Introduced in Easy Digital Downloads version 2.1, the EDD_Emails class handles the construction and sending of purchase receipts and admin sale notifications. It is also used by extensions to send custom emails in the standard HTML template.

To send an email using the EDD_Emails, class, call the send() method from the main EDD() instance, like this:

EDD()->emails->send( $to, $subject, $message );

If you want to send attachments along with the email, pass the file paths as a string or array as a fourth parameter:

EDD()->emails->send( $to, $subject, $message, $attachments );

All emails sent through this class will have the template selected in Downloads > Settings > Emails applied. By default, it looks like this:

Screenshot from 2014-09-03 10:36:07

Class properties:

  • $from_address
  • $from_name
  • $content_type
  • $headers
  • $html
  • $template
  • $heading

Methods:

  • public: __set( $key, $value )
  • public: get_from_name()
  • public: get_from_address()
  • public: get_content_type()
  • public: get_headers()
  • public: get_templates()
  • public: get_template()
  • public: get_heading()
  • public: parse_tags()
  • public: build_email()
  • public: send()
  • public: send_before()
  • public: send_after()
  • public: text_to_html()

Filters:

  • edd_email_from_name
  • edd_email_from_address
  • edd_email_content_type
  • edd_email_headers
  • edd_email_templates
  • edd_email_template
  • edd_email_heading
  • edd_email_message
  • edd_email_attachments

Actions:

  • edd_email_header
  • edd_email_template_{template name}
  • edd_email_body
  • edd_email_footer
  • edd_email_send_before
  • edd_email_send_after

The post EDD_Emails first appeared on Easy Digital Downloads.

]]>
EDD_Fees Class https://easydigitaldownloads.com/docs/edd_fees-class/ Mon, 24 Jan 2022 19:57:37 +0000 https://edd-site.lndo.site/docs/edd_fees-class/ The  EDD_Fees class can be used to add arbitrary fees to the shopping cart, both positive and negative (discount) fees. For example, you could add a special 10% off fee automatically for all registered users that have a certain user role, or add a “handling” fee for all products inside of a certain category. The

The post EDD_Fees Class first appeared on Easy Digital Downloads.

]]>
The  EDD_Fees class can be used to add arbitrary fees to the shopping cart, both positive and negative (discount) fees. For example, you could add a special 10% off fee automatically for all registered users that have a certain user role, or add a “handling” fee for all products inside of a certain category. The options are limitless.

This class is only available in EDD v1.5+

Fees are stored as session variables, which means once they’re set for a user they’ll persist until either the user checks out or they’re removed by some code based on a decision or setting.

Types of fees

Fees can have two types:

fee
This is just what it sounds like, an additional cost or discount added to the subtotal of purchases.
item
This is a fee that is not associated with anything else, think of it like a temporary product made up on the spot. Currently used for Wallet deposits for example.

Note: negative fees always set no_tax to true.

add_fee()

Adding an expense or giving a discount are both considered adding fees, despite the fact that one of them is removing money.

Adding a fee is done with code similar to this:

function pw_set_admin_discount() {
    // check to see the customer is a site admin
    if( current_user_can( 'manage_options' ) ) {
	// find 20% of the total
        $amount = edd_get_cart_subtotal() * 0.20;

	// flip the 20% from a positive number to a negative number
        $amount = $amount * -1;

	// Add the fee, sending the amount, the reason printed to the front end, and the handle
        EDD()->fees->add_fee( $amount, 'You are an admin special!', 'admin_special' );
    }
}
// run this code on site init
add_action( 'init', 'pw_set_admin_discount' );

This example automatically adds a 20% discount if the current user is an admin.

Here’s another example that adds a handling fee:

function pw_add_handling_fee() {
	// Add a $10 handling fee no matter what
	EDD()->fees->add_fee( '10', 'Handling Fee', 'handling_fee' );
}
add_action( 'init', 'pw_add_handling_fee' );

The first parameter is the fee amount, the second parameter is the label (as shown on the checkout/purchase history screens), and the third parameter is the fee ID.

Here’s a screenshot of both of the above examples being applied at the same time:

The above examples were for simply adding arbitrary fees, but add_fees() can also take the following arguments:

$args = array(
	'price_id'    => $price_id,
	'amount'      => $amount,
	'label'       => $label,
	'id'          => $id,
	'type'        => $type,
	'no_tax'      => false,
	'download_id' => 0
);

remove_fee()

To remove a fee, simply pass the fee ID (third parameter above) to the remove_fee() method:

function pw_remove_handling_fee() {
	EDD()->fees->remove_fee( 'handling_fee' );
}
add_action( 'init', 'pw_remove_handling_fee', 9999 );

Other Methods

In addition to simply adding and removing fees there are a number of methods for working with fees on the back end.

has_fees( string $type = ‘fee’  )

This method simply checks to see if any fees exist.  Defaults to the fee type, but can accept item as well.

Example:

if ( EDD()->fees->has_fees() ) {
	echo 'yep, we can haz fees!';
}

Returns: true or false.

get_fees( string $type = ‘fee’, integer $download_id = 0  )

This method will get an array of all existing fees.  It can be limited by type and/or download id.

Example

The  Simple Shipping extension is a perfect example of how the EDD_Fees class can be used.

$fees = EDD()->fees->get_fees();

Returns something like this:

Array
(
    [handling_fee] => Array
        (
            [amount]      => 11.00
            [label]       => Handling Fee
            [type]        => fee
            [no_tax]      => 
            [download_id] => 0
            [price_id]    =>
        )

    [admin_special] => Array
        (
            [amount]      => -2
            [label]       => You are an admin special!
            [type]        => fee
            [no_tax]      => 
            [download_id] => 0
            [price_id]    =>
        )

    [tophers_fee] => Array
        (
            [amount]      => 42.00
            [label]       => Topher's fee
            [no_tax]      => 
            [type]        => fee
            [download_id] => 114
            [price_id]    =>
        )

)
get_fee( string $id = ”  )

This method will get an array of a specific fee, identified by the name it was given when it was created.  

Example: 

$my_custom_fee = EDD()->fees->get_fee( 'my_custom_fee' );

Returns something like this:

 Array
(
    [amount] => 42.00
    [label] => The Final Fee
    [no_tax] => 
    [type] => fee
    [download_id] => 114
)
type_total( string $type = ‘fee’  )

This method calculate the total for a specific type of fee.  The types supported are ‘fee’ and ‘item’.

Example: 

$item_total = EDD()->fees->type_total( 'item' );

Returns an number like 51.00

total( integer $download_id = 0  )

This method calculate the total for all fees OR all fees specifically attached to a given download.

Note: If a product has fees and variable prices, The fee will only be applied once per transaction, NOT once per item.

Example:

$total = EDD()->fees->total();

$total = EDD()->fees->total( '42' );

In the example above, the first would return a number like 51.00 that is the sum of all fees.

The second example would return a number like 51.00 that is the sum of all fees tied specifically to the Download with the ID of 42.

record_fees( array $payment_meta, array $payment_data )

This method records the fee information about a specific transaction.  It should never be called directly.

The post EDD_Fees Class first appeared on Easy Digital Downloads.

]]>
EDD_HTML_Elements https://easydigitaldownloads.com/docs/edd_html_elements/ Mon, 24 Jan 2022 19:57:34 +0000 https://edd-site.lndo.site/docs/edd_html_elements/ The EDD_HTML_Elements class provides a series of helper methods for rendering commonly used HTML fields with consistent markup, class names, and attributes. The class includes methods for the following field types: product_dropdown() This method creates a select html element with products in it. Values are product_ids and the text is Download titles. Example: echo EDD()->html->product_dropdown();

The post EDD_HTML_Elements first appeared on Easy Digital Downloads.

]]>
The EDD_HTML_Elements class provides a series of helper methods for rendering commonly used HTML fields with consistent markup, class names, and attributes.

The class includes methods for the following field types:

product_dropdown()

This method creates a
select html element with products in it. Values are product_ids and the text is Download titles.

Example:

echo EDD()->html->product_dropdown();

This would create a drop down list of products.  The method takes one input, an array, and has these defaults:

$defaults = array(
	'name'        => 'products',
	'id'          => 'products',
	'class'       => '', 
	'multiple'    => false,
	'selected'    => 0,
	'chosen'      => false,
	'number'      => 30, 
	'bundles'     => true,
	'placeholder' => sprintf( __( 'Select a %s', 'easy-digital-downloads' ), edd_get_label_singular() )
);

Here’s a description of what’s in each option:

name

This would be the html “name” property of the form element.  Defaults to ‘products’.

Example:


class

This would be the “class” property of the html element.  Defaults to nothing.

Example:


id

This would be the html “id” property of the html element.  Defaults to ‘customers’.

Example:


multiple

This makes the select menu be of the “multiple” type. Defaults to false.

Example:

selected

This allows you to provide a customer_id and have that one be pre-selected when the form loads.  Defaults to 0.

chosen

This activated the “chosen” jquery plugin on your select box.  Defaults to false.

Examples both closed and open:

number

This allows you to set a limit to the number of customers in your list.  Defaults to 30.

placeholder

This is the text that goes in the first line of the select list, usually something like a title. The default is “Select a Customer”.

discount_dropdown()

This method creates a
select html element with a list of Discounts in it. Values are discount_ids and the text is the title of the Discount.

Example:

echo EDD()->html->discount_dropdown();

This would create a drop down list of discounts.

Input

This method takes three values as input.

name

This is the name of the html element.  The default is ‘edd_discounts’

selected

This is the item that should be selected when the select box loads.  The default is to have nothing set to be selected, and the default item will be the first discount on the list.

status

Discounts can be active or inactive.  The ‘status’ option allows a choice of either one.  The default is to not declare, and all Discounts are loaded.

category_dropdown()

This method creates a
select html element with a list of Download categories in it. Values are term_ids and the text is the title of the category.

Example:

echo EDD()->html->category_dropdown();

This would create a drop down list of Download categories.

Input

This method takes two values as input.

name

This is the name of the html element.  The default is ‘edd_categories’

selected

This is the item that should be selected when the select box loads. The default is to have nothing set to be selected, and the select box will have an option titled “All Categories”.

year_dropdown()

This method creates a
select html element with a list of years in it. Text and option value are both a 4 digit year.

Example:

echo EDD()->html->year_dropdown();

This would create a drop down list of 6 years, current year selected by default.

Input

This method takes two values as input.

name

This is the name of the html element.  The default is ‘year’

selected

This is the item that should be selected when the select box loads.  Requires a four digit integer.

month_dropdown()

This method creates a
select html element with a list of months in it. Values are unpadded integers and text is three letter abbreviations of months.

Example:

echo EDD()->html->year_dropdown();

This would create a drop down list of 12 months, current month selected by default.

Input

This method takes two values as input.

name

This is the name of the html element.  The default is ‘month’

selected

This is the item that should be selected when the select box loads. Requires a two digit integer.

select()

This method creates a
select html element and allows you to populate it with any single dimensional array.

Example:

echo EDD()->html->select( $args );

The method takes one input, an array, and has these defaults:

$args = array(
    'options'          => array(),
    'name'             => null,
    'class'            => '',
    'id'               => '',
    'selected'         => 0,
    'chosen'           => false,
    'placeholder'      => null,
    'multiple'         => false,
    'show_option_all'  => _x( 'All', 'all dropdown items', 'easy-digital-downloads' ),
    'show_option_none' => _x( 'None', 'no dropdown items', 'easy-digital-downloads' ),
);

Here’s a description of what’s in each option:

options

This is a single dimensional array of things like this:

$args['options'] = array(
    '1' => 'Thing 1',
    '2' => 'Thing 2',
    '3' => 'Thing 3',
    '4' => 'Thing 4',
);

The array keys are used as the select option values, and the array values are used as the select option text.

name

This would be the html “name” property of the form element.  Defaults to null, required to make a useful form element.

id

This would be the html “id” property of the html element.  Defaults to empty.

class

This would be the “class” property of the html element.  Defaults to empty.

multiple

This makes the select menu be of the “multiple” type. Defaults to false.

Example:

selected

This allows you to provide a key from your array and have that one be pre-selected when the form loads.  Defaults to 0.

chosen

This activated the “chosen” jquery plugin on your select box.  Defaults to false.

Examples both closed and open:

placeholder

This is the text that goes in the first line of the select list, usually something like a title. The default is null.

show_option_all

This creates a select option with a value of “all”, and is inserted into the argument list this way:

'show_option_all'  => _x( 'All', 'all dropdown items', 'easy-digital-downloads' ),
show_option_none

This creates a select option with a value of “-1”, and is inserted into the argument list this way:

'show_option_all'  => _x( 'None', 'no dropdown items', 'easy-digital-downloads' ),

checkbox()

This method creates a single
checkbox html element.

Note: This function does not create any wrapping HTML like .

Example:


The method takes one input, an array, and has these defaults:

$args = array(
    'name'     => null,
    'current'  => null,
    'class'    => 'edd-checkbox',
    'options'  => array(
        'disabled' => false,
        'readonly' => false
    )   
);

Here’s a description of what’s in each option:

name

This would be the html “name” property of the form element.  Defaults to null, required to make a useful form element.

Note: the name is also used for the ‘id’.

current

This is the pre-existing value of the field. It’s used to determine if the checkbox should default to checked.

class

This is the value of the ‘class’ html element. Defaults to ‘edd-checkbox’.

options

This needs to be an array, and can hold two options.

  • disabled – Sets the field to disabled or not with true or false.
  • readonly – Sets the field to readonly or not with true or false.

text()

This method creates a plain text html element.

Example:

html->text( $args ); ?>

The method takes one input, an array, and has these defaults:

$args = array(
    'id'           => '',  
    'name'         => 'text', 
    'value'        => NULL, 
    'label'        => NULL, 
    'desc'         => NULL, 
    'placeholder'  => '',  
    'class'        => 'regular-text',
    'disabled'     => false,
    'autocomplete' => '',
    'data'         => false
);

Here’s a description of what’s in each option:

id

This would be the html “id” property of the html element.  Defaults to empty.

name

This would be the html “name” property of the form element.  Defaults to “text”.

value

This is the pre-existing value of the field. It’s used to pre-fill the text field with this value. Defaults to NULL.

label

This is the text wrapped in a

desc

This is text that is wrapped in a span with a class of “edd-description”.  It’s placed between the label and the input.  Defaults to NULL.

placeholder

This text is placed in the “placeholder” element of the .  Rendering depends on the browser.  
You can read more about the placeholder element at w3schools.  Default is empty.

class

This is the value of the ‘class’ html element. Defaults to ‘regular-text’.

disabled

This sets the field to disabled or not.  Boolean, defaults to false.

autocomplete

This sets the autocomplete element to “on” or “off”.  Defaults to empty, which equates to on in most modern browsers.

data

This accepts an array, and creates data html elements from the array. Example:

array(
	'price' => '42.00',
	'variable-price' => 'no',
);

The above array would result in this html being places inside the input:

data-price="42.00" data-variable-price="no"

Defaults to false.

textarea()

This creates a standard multi-line HTML textarea.

Example:

html->textarea( $args ); ?>

The method takes one input, an array, and has these defaults:

$args = array(
    'name'        => 'textarea',
    'value'       => null,
    'label'       => null,
    'desc'        => null,
    'class'       => 'large-text',
    'disabled'    => false
);

Here’s a description of what’s in each option.

name

This would be the html “name” property of the form element.  Defaults to “textarea”.

value

This is the pre-existing value of the field. It’s used to pre-fill the text field with this value. Defaults to NULL.

label

This is the text wrapped in a

desc

This is text that is wrapped in a span with a class of “edd-description”.  It’s placed after the textarea tag.  Defaults to NULL.

class

This is the value of the ‘class’ html element. Defaults to ‘large-text’.

disabled

This sets the field to disabled or not.  Boolean, defaults to false.

ajax_user_search()

This method creates a text field for searching for EDD users.  It uses ajax to search as you type, and allows you to click to choose a result to populate the field.

Note: this field only works on EDD admin pages.  Not the front of WordPress, and not other WordPress admin areas.

Example:

html->ajax_user_search( $args ); ?>

The method takes one input, an array, and has these defaults:

$args = array(
    'name'        => 'user_id',
    'value'       => NULL,
    'placeholder' => __( 'Enter username', 'easy-digital-downloads' ),
    'label'       => NULL,
    'class'       => '',  
    'disabled'    => false,
    'autocomplete'=> 'off',
);

Here’s a description of what’s in each option.

name

This would be the html “name” property of the form element.  Defaults to “user_id”.

value

This is the pre-existing value of the field. It’s used to pre-fill the text field with this value. Defaults to NULL.

placeholder

This text gets rendered in the input box in most browsers. Defaults to:

__( 'Enter username', 'easy-digital-downloads' )
label

This text does not appear on the front of the site, but is used with aria for screen readers. Defaults to NULL.

class

This is the value of the ‘class’ html element. Defaults to empty.

disabled

This sets the field to disabled or not.  Boolean, defaults to false.

autocomplete

This sets the autocomplete element to “on” or “off”.  Defaults to empty, which equates to on in most modern browsers.

The post EDD_HTML_Elements first appeared on Easy Digital Downloads.

]]>
EDD_Customer https://easydigitaldownloads.com/docs/edd_customer/ Mon, 24 Jan 2022 19:57:12 +0000 https://edd-site.lndo.site/docs/edd_customer/ Table of Contents Getting a Customer Getting Customer Payment Data Creating a Customer Updating a Customer Updating Specific Fields Customer Meta Customer Email Addresses The EDD_Customer class is used for getting customer data, creating new customer entries, and editing existing customer entries. The values that may be managed with this class are: user_id name email

The post EDD_Customer first appeared on Easy Digital Downloads.

]]>
Table of Contents

The EDD_Customer class is used for getting customer data, creating new customer entries, and editing existing customer entries. The values that may be managed with this class are:

  • user_id
  • name
  • email
  • payment_ids
  • purchase_value
  • purchase_count
  • notes

Getting a Customer

Your reasons for getting Customer data can vary from simply rendering the info to using it for stats or logging or anything else. Here are the steps to get and render customer information.

Step 1, Get the data

In order to create a Customer object you must pass some sort of identifier when instantiating the class. This can be email address, Customer ID, or WordPress user ID.

Examples:

Email

$customer = new EDD_Customer( 'jose@canseco.com' );

Customer ID

$customer = new EDD_Customer( 33 );

WordPress user ID

$customer = new EDD_Customer( 96, true );

Note: for the WordPress user ID you must pass a value of true as the second parameter, so that it knows to look at WordPress rather than EDD.

Step 2, Use the data

Now you can access properties of the customer object like this:

  • $customer->name;
  • $customer->email;
  • $customer->date_created;
  • $customer->purchase_count;
  • $customer->purchase_value;
  • $customer->id; // Customer ID
  • $customer->user_id; // WordPress user ID
  • $customer->payment_ids;

You can echo those, parse them; anything you wish.

Getting Customer Payment Data

The EDD_Customer class has a method called
get_payments(). This method will return an array of EDD_Payment objects. Example:

$customer = new EDD_Customer( 33 );

$payments = $customer->get_payments();

Now $payments will hold an array of EDD_Payment objects. For more information on what that array looks like,
please see the docs on the EDD_Payment class.

Creating a Customer

First instantiate an object:

$customer = new EDD_Customer;
Example 1:
Then set up some arguments:
$args = array(
	'user_id'        => 12
	'name'           => 'Jose Canseco',
	'email'          => 'jose@canseco.com',
	'payment_ids'    => '',
	'purchase_value' => '',
	'purchase_count' => '',
	'notes'          => 'Whatever note you'd like',
);

Note: the
user_id above is a WordPress user ID number. It is only required if you want to associate your Customer with a WordPress user. If not, remove it from the array.

And then run the create method:
$customer->create( $args );
And now at this point your Customer should exist.
Example 2:
The above example shows how to create a customer with all possible options. The only
required option is email, so this would work as well:
$args = array(
	'email' => 'jose@canseco.com',
);
$customer->create( $args );

This creates a customer with only the email address provided, which works just fine.

Updating a Customer

Step 1, Get The Data.

Use the example code from “Getting A Customer” above.

Step 2, Update The Data

There are two ways of updating customer data with EDD_Customer. One is to use the
update() method and update multiple fields at one time.

Example:

$customer = new EDD_Customer( 33 );

$update_args = array(
	'email'          => 'jose@canseco.com',
	'name'          => 'Jose Canseco',
);

Now customer 33 has an updated email address and a new note.

Note: updating the notes field with this method will wipe out any existing notes. Use the add_note() method mentioned below to add a new note.

Updating Specific Fields

Rather than using the general update() method listed above you should generally try to use one of the helper methods provided below. These provide specific limited functionality that can help reduce errors.

For each of the following methods you would first instantiate the customer class as above:

$customer = new EDD_Customer( 33 );

attach_payment() and remove_payment()

These are used for attaching and removing payments to and from a customer. They both take a payment_id as the first variable, and a boolean option as the second. The second will update stats if set to true.

Examples:


$customer->attach_payment( 33, true );

$customer->remove_payment( 33, true );

increase_purchase_count() and decrease_purchase_count()

These are used to increase and decrease the
number of purchases made by a single customer. They both simply take an integer, changing the stored value by that much.

Examples:

$customer->increase_purchase_count( 1 );

$customer->decrease_purchase_count( 1 );

increase_value() and decrease_value()

These are used to increase and decrease the amount spent by a single customer. They both simply take a decimal number, to two places, changing the stored value by that much.

Examples:
$customer->increase_value( 14.98 );
$customer->decrease_value( 3.00 );

get_notes()

This method returns notes left on the customer’s account. It accepts 2 variables, the first for how many notes you want, and the second is an offset.

Examples:
$customer->get_notes( 5 ); // gets the first 5 notes
$customer->decrease_value( 5, 6 ); // gets 5 notes starting at position 6, so notes 6-10

get_notes_count()

This method returns the number of notes on the customer’s account. It takes no input.

Example:
$customer->get_notes_count();

add_note()

This method accepts a string as input, and stores it as a new note on the customer’s account. It preserves hard returns, but does not allow HTML.

Example:

$customer->add_note( 'This is a note. Isn't that cool?' );

Customer Meta

Arbitrary customer meta may be managed using the meta functions built into the EDD_Customer class.

get_meta( $meta_key = ”, $single = true )

get_meta simply takes a meta key and returns the value. If single is set to false it will always return an array.

add_meta( $meta_key = ”, $meta_value, $unique = false )

add_meta accepts a meta_key and its value, but it also accepts a boolean for unique. If the third input is true then add_meta will only succeed if the meta_key does not previously exist. Returns false for failure. True for success.

update_meta( $meta_key = ”, $meta_value, $prev_value = ” )

update_meta accepts a meta_key and the new value you wish to set for it. If you have multiple keys of the same name they will all be updated with the new value. The third input accepts a value to compare the previous value against. So if you already have several meta_keys of
foo but only one with a value of bar, you could make bar the third input and the update would only occur on that one. Returns false for failure. True for success.

delete_meta( $meta_key = ”, $meta_value = ” )

delete_meta will delete all meta data with a matching key. If a value is also passed then both must match. Returns false for failure. True for success.

Customer Email Addresses

Each customer can have multiple email addresses, allowing them to purchase from more than one address, or purchase from one and get support from another. Each customer will also have a primary email address, which gets used as a default for the customer. In the Customer Management tab the UI looks like this:

The EDD_Customer class allows the developer to removes addresses from a customer and add addressed to a customer as well as make a specific address primary.

add_email( $email = ”, $primary = false )

This function accepts an email address to add to the customer. If the second input is true, the new email address will be set as the primary address for the customer. Returns false for failure. True for success.

set_primary_email( $new_primary_email = ” )

This function accepts an email address and if the email address is already attached to this customer it will make it the primary email address for that customer. Returns false for failure. True for success.

remove_email( $email = ” )

This function accepts an email address and if the email address is already attached to this customer it removes it from that customer. Returns false for failure. True for success.

The post EDD_Customer first appeared on Easy Digital Downloads.

]]>
EDD_Download https://easydigitaldownloads.com/docs/edd_download/ Mon, 24 Jan 2022 19:57:04 +0000 https://edd-site.lndo.site/docs/edd_download/ The EDD_Download class is used for getting data about a specific Download, creating new Downloads, and editing existing Downloads.  The public properties that may be managed with this class are: Note: The above properties are inherited from and identical to the properties in WP_Post. Creating a Download To create a new download you first instantiate

The post EDD_Download first appeared on Easy Digital Downloads.

]]>
The EDD_Download class is used for getting data about a specific Download, creating new Downloads, and editing existing Downloads.  The public properties that may be managed with this class are:

  • $ID = 0;
  • $post_author = 0;
  • $post_date = ‘0000-00-00 00:00:00’; 
  • $post_date_gmt = ‘0000-00-00 00:00:00’; 
  • $post_content = ”;
  • $post_title = ”;
  • $post_excerpt = ”;
  • $post_status = ‘publish’; 
  • $comment_status = ‘open’;
  • $ping_status = ‘open’;
  • $post_password = ”;
  • $post_name = ”;
  • $to_ping = ”;
  • $pinged = ”;
  • $post_modified = ‘0000-00-00 00:00:00’; 
  • $post_modified_gmt = ‘0000-00-00 00:00:00’; 
  • $post_content_filtered = ”;
  • $post_parent = 0;
  • $guid = ”;
  • $menu_order = 0;
  • $post_mime_type = ”;
  • $comment_count = 0;
  • $filter;

Note: The above properties are inherited from and identical to the properties in WP_Post.

Creating a Download

To create a new download you first instantiate the class and then run the create() method.

$new_download = new EDD_Download;
$new_download->create();

This will create a single Download with default settings, which are a Draft with the title of ‘New Download Product’.

The create method uses 
wp_insert_post(), so you may pass any arguments to create() that wp_insert_post() can accept.  Something like this would work fine:

$new_download = new EDD_Download;

$download_args = array(
	'post_title'    => 'My eBook',
	'post_content'  => 'This is my eBook. Nice long description.',
	'post_status'   => 'publish',
)
$new_download->create( $download_args );

Loading an Existing Download

This is accomplished simply by passing a Download ID to the class name during instantiation.

Example:

$my_download = new EDD_Download( 1492 );

Data Fetching Methods

EDD_Download has a variety of method for getting data about the Download, manipulating meta data, and testing for various things.

get_ID()

This method simply returns the ID of the Download.

Example:

$download_id = $my_download->get_ID();

Returns: an integer, like 1492.

get_price()

This method returns the price of the Download in double format, with no currency symbol.

Example:
$download_price = $my_download->get_price();

Returns: a double, like 9.99. Math may be done on this result.

get_prices()

This method returns an array of the variable prices of the Download in double format, with no currency symbol.

Example:
$variable_prices = $my_download->get_prices();

Returns an array of prices like this:

Array
(
    [1] => Array
        (
            [index] => 1
            [name] => Regular
            [amount] => 9.99
        )

    [2] => Array
        (
            [index] => 
            [name] => Unleaded
            [amount] => 19.99
        )
is_single_price_mode()

Determines whether Single Price Mode is enabled or disabled.  Single price mode refers to whether multiple price options can be purchased simultaneously.  In the Easy Digital Downloads user interface the checkbox for it is under Variable Pricing.

Example:
$is_single_price_mode = $my_download->is_single_price_mode();

Returns: true or false

has_variable_prices()

Determines whether Variable Pricing is enabled or disabled on a specific Download.

Example:
$download_price = $my_download->has_variable_prices();

Returns: true or false

get_files()

This method returns an array of the files attached to the Download

Example:
$my_files = $my_download->get_files();

Returns an array of prices like this:

Array
(
    [0] => Array
        (
            [attachment_id] => 10
            [name] => Be Kind To Your Web Footed Friends
            [file] => http://example.com/wp-content/uploads/edd/2015/05/be_kind_to_your_web_footed_friend.mp3
            [condition] => all
        )

)
get_file_download_limit()

This method gets the number of times this file may be downloaded.

Example:

$download_limit = $my_download->get_file_download_limit();

Returns: an integer, like 100.

get_file_price_condition()

When a product has variable pricing, one or more files may available for purchase. Under the Price Assignment, Files can be associated with All price options or only specific ones.  In the example below the file is associated with Tracks 1, 2, 3 and Full Album.

Example:

$price_condition = $my_download->get_file_price_condition();

Returns: an integer, like 2.

get_type()

Returns value showing whether the Download is a Bundle or Default.

Example:

$download_type = $my_download->get_type();

Returns: either ‘default’ or ‘bundle’

is_bundled_download()

Determine if this is a bundled download.

Example:

$is_bundled_download = $my_download->is_bundled_download();

Returns: true or false

get_bundled_downloads()

Gets the Download ids of the items in a bundled Download.

Example:

$bundled_downloads = $my_download->get_bundled_downloads();

Returns: An array of Download ids like this:

Array
(
    [0] => 68
    [1] => 114
)

Note: get_bundled_downloads() will return an empty array if the product is not a bundle, so look at doing something like this:

if ( $my_download->is_bundled_download() ) {
	$bundled_downloads = $my_download->get_bundled_downloads();
}
get_notes()

Returns the notes for a Download as a string.

Example:

$download_notes = $my_download->get_notes();

Returns: The notes as a string, and maintains line breaks.

get_sku()

Returns the sku for a Download as a string.

Example:

$download_sku = $my_download->get_sku();

Returns: The sku as a string

get_button_behavior()

Returns the what happens when someone clicks the buy button

Example:

$download_button_behavior = $my_download->get_button_behavior();

Returns: either ‘direct’ for Buy Now or ‘add_to_cart’ for Add To Cart.

get_sales()

Returns the number of sales completed for this item

Example:

$download_sales = $my_download->get_sales();

Returns: an integer like 42

increase_sales()

Increments the number of sales by 1. Cannot take input, cannot increase by more than 1.

Example:

$increase_sales = $my_download->increase_sales();

Returns: either false on failure or an integer of the new sales count.

decrease_sales()

Decrements the number of sales by 1. Cannot take input, cannot increase by more than 1.

Example:

$decrease_sales = $my_download->decrease_sales();

Returns: either false on failure or an integer of the new sales count.

get_earnings()

Returns the total earning for this download.

Example:

$download_earnings = $my_download->get_earnings();

Returns: a float like 152.69

increase_earnings( mixed $amount = 0 )

Increases the total earnings for a Download by the input amount.

Example:

$increase_earnings = $my_download->increase_earnings();

Returns: either false on failure or a float of the new amount, like 247.39

decrease_earnings( mixed $amount = 0 )

Decreases the total earnings for a Download by the input amount.

Example:

$decrease_earnings = $my_download->decrease_earnings();

Returns: either false on failure or a float of the new amount, like 147.39

is_free( mixed $price_id = false )

Checks to see if the download is free, OR if the given price ID is free.

Example:

$is_free = $my_download->is_free();

Returns: true or false

The post EDD_Download first appeared on Easy Digital Downloads.

]]>
EDD_Payment https://easydigitaldownloads.com/docs/edd_payment/ Mon, 24 Jan 2022 19:57:02 +0000 https://edd-site.lndo.site/docs/edd_payment/ Table of Contents Available Properties Available Methods Examples The EDD_Payment class makes it easy to create, edit, and delete payment information in Easy Digital Downloads. Here are some examples: Example of creating a new payment $payment = new EDD_Payment(); $payment->add_download( 97 ); $payment->email = 'steve@example.com'; $payment->status = 'complete'; $payment->save(); Example of updating the email on

The post EDD_Payment first appeared on Easy Digital Downloads.

]]>
Table of Contents

The EDD_Payment class makes it easy to create, edit, and delete payment information in Easy Digital Downloads. Here are some examples:

Example of creating a new payment
$payment = new EDD_Payment();
$payment->add_download( 97 );
$payment->email = 'steve@example.com';
$payment->status = 'complete';
$payment->save();
Example of updating the email on an existing payment:
$payment = new EDD_Payment( 4023 );
$payment->email = 'steve@example.com';
$payment->save();

Available Properties

These are the properties which are available to your object:

  • $ID
  • $number
  • $mode
  • $key
  • $total
  • $subtotal
  • $tax
  • $fees
  • $discounts
  • $date
  • $completed_date
  • $status
  • $old_status
  • $status_nicename
  • $customer_id
  • $user_id
  • $first_name
  • $last_name
  • $email
  • $address
  • $transaction_id
  • $downloads
  • $ip
  • $gateway
  • $currency
  • $cart_details
  • $has_unlimited_downloads
  • $pending
  • $parent_payment

Available Methods

add_download( $download_id = 0, $args = array(), $options = array() )

This method allows you to add a download to a payment. It accepts three arguments:

$download_id

This is the ID of the download you wish to attach. It’s always an integer.

$args

This is an array that can over-ride these built in defaults:

            'quantity'    => 1,
            'price_id'    => false,
            'item_price'  => 0.00,
            'tax'         => 0.00,
            'fees'        => array()

Fees may be anything required, but follows the format of
add_fee(). For more information see the docs for EDD_Fees.

$options

This is an array that can accept arbitrary options for the download. Examples might be
is_renewal or is_upgrade for the Software Licensing extension.

IMPORTANT: if you add a download to a Completed payment the new download will be set to a zero price. If you add a download to a payment with any other status, that download carries its default financial value, and the total value of the payment increases.

This default behavior may be over-ridden by sending an
item_price in the $args.

remove_download( $download_id, $args = array() )

This method allows you to remove a download from a payment. It accepts two arguments:

$download_id

This is the ID of the download you wish to attach. It’s always an integer.

$args

This is an array that can over-ride these built in defaults:

            'quantity'    => 1,
            'price_id'    => false,
            'item_price'  => 0.00,
            'cart_index'  => false,

NOTE: if your download is variable then the price_id is required so that the proper item is removed.

NOTE: By default remove_download() only removes one item. If you have multiple of the same item you’ll need to use the quantity option in the $args.

get_meta( $meta_key = ‘_edd_payment_meta’, $single = true )

This method gets the meta data associated with a payment. It accepts a meta key and a boolean to request the meta data in single mode or not.

Internally this method runs get_post_meta, but then applies some logic to provide backwards compatibility with EDD 1.5

It then runs apply_filters on
'edd_get_payment_meta_' . $meta_key and then returns the output after one more filter of edd_get_payment_meta

update_meta( $meta_key = ”, $meta_value = ”, $prev_value = ” )

This method allows you to update the post meta for a payment. It accepts a meta key, meta value, and a previous meta value for comparison.

Before updating, the meta_key is run through a filter called
'edd_update_payment_meta_' . $meta_key.

The return value is the output of
update_post_meta.

add_fee( $args = ”, $global = true )

This method allows you to attach an arbitrary fee to the payment. It functions exactly like the one in EDD_Fees, please read the documentation there.

remove_fee( $key )

This method allows you to remove a given fee. It functions exactly like the one in EDD_Fees,
please read the documentation there.

remove_fee_by( $key, $value, $global = false )

This method allows you to remove a fee without having to know its position in the fees array. For example, if you have a fee with a label of shipping you could do something like

$payment->remove_fee_by( 'label', 'Shipping' );

The above code would remove the first instance of a a fee with a label of Shipping. If you add the gobal true flag like this:

$payment->remove_fee_by( 'label', 'Shipping', true );

then it’ll remove ALL fees with a label of Shipping.

add_note( $note = false )

This method allows you to attach a note to the payment. Results will look something like this:

update_status( $status = false )

This method allows you to set the status of a given payment. Here are the possible statuses:

  • Pending
  • Complete
  • Refunded
  • Failed
  • Abandoned
  • Revoked

array_convert()

This method allows you to get all available properties as an array. Example:

$payment = new EDD_Payment( 4577 );
$payments_array = $payment->array_convert();

IMPORTANT: properties that have been moved to an array with array_convert will NOT be updated inside that array. If you need an updated version after a change you would need to re-run this method and re-populate your array.

save()

This method takes any changes or updates made by any other method and writes them to the database.

NOTE: if you don’t use save() then none of your changes will actually take place.

Examples

Here are some code examples of some common tasks:

Creating a payment

$payment = new EDD_Payment(); // Instantiates a payment object
$payment->add_download( 12 ); // Adds download id 12 to the payment at it's default price
$payment->email = 'lisa@example.org'; // Email is required for a payment
$payment->status = 'complete'; // Completes the payment
$payment->save(); // Writes to the database any changes that were made

Editing an existing payment

$payment = new EDD_Payment( 42 ); // Loads the information for Payment ID 42
$payment->email = 'john@example.org'; // Changes the email address on the payment
$payment->save();

Changing a payment status

$payment = new EDD_Payment( 1337 );
$payment->status = 'revoked';
$payment->save();

Adding a variable priced download

$payment = new EDD_Payment( 1942 );
$args = array(
    'price_id' => 1, // Variable price ID
    'item_price' => 0.00, // Makes the item free
);
$payment->add_download( 23, $args ); // Adds Download ID 23, variable price 1 to the payment
$payment->save();

Adding a download with options

$payment = new EDD_Payment( 2008 );
$args = array(
    'item_price' => 4.00,
);
$options = array(
    'is_renewal' => true,
);
$payment->add_download( 28, $args, $options );
$payment->save();

Removing a download

$payment = new EDD_Payment( 2008 );
$payment->remove_download( 23 );
$payment->save();

Removing a download with variable pricing

$payment = new EDD_Payment( 2008 );
$args = array(
    'price_id' => 1,
);
$payment->remove_download( 28, $args );
$payment->save();

The post EDD_Payment first appeared on Easy Digital Downloads.

]]>
EDD API Reference https://easydigitaldownloads.com/docs/edd-api-reference/ Mon, 24 Jan 2022 19:57:01 +0000 https://edd-site.lndo.site/docs/edd-api-reference/ This document has been replaced with newer information at https://easydigitaldownloads.com/docs/edd-api-reference/. Please use the new documentation for all future research.

The post EDD API Reference first appeared on Easy Digital Downloads.

]]>
This document has been replaced with newer information at
https://easydigitaldownloads.com/docs/edd-api-reference/.

Please use the new documentation for all future research.

The post EDD API Reference first appeared on Easy Digital Downloads.

]]>