rcp_get_discounts()

Query for discount codes.

Parameters:

  • $args (array) - Array of arguments, all of which are optional:
    • $id (int) - A discount ID to only return that discount. Default empty.
    • $id__in (array) - An array of discount IDs. Default empty.
    • $id__not_in (array) - An array of discount IDs to exclude from the results. Default empty.
    • $name (string) - The name of a discount code.
    • $amount (int|float|string) - Filter by the discounted amount.
    • $unit (string) - Filter by unit ("percentage" or "flat").
    • $code (string) - Filter by discount code.
    • $status (string) - Filter by discount status ("active" or "disabled").
    • $one_time (int) - Set to `1` to only retrieve one-time discounts. Set to `0` to only retrieve recurring discounts. Omit to retrieve all.
    • $expiration_query (array) - Filter by expiration date. See WP_Date_Query for supported formats. Default empty.
    • $date_created_query (array) - Filter by the date the discount code was created. See WP_Date_Query for supported formats. Default empty.
    • $date_modified_query (array) - Filter by the date the discount code was last modified. See WP_Date_Query for supported formats. Default empty.
    • $count (bool) - True to return the number of results, false to return an array of RCP_Discount objects. Default false.
    • $fields (array) - Array of fields to return. Accepts any known column names or empty to return RCP_Discount objects. Default empty.
    • $number (int) - The number of results to retrieve. Default 20.
    • $offset (int) - Number of discounts to offset the query. Default 0.
    • $orderby (string) - Column to order results by. Accepts `id`, `name`, `code`, `use_count`, `max_uses`, `status`, `expiration`, `date_created`, and `date_modified`. Default `id`.
    • $order (string) - How to order results. Accepts `ASC` and `DESC`. Default `DESC`.
    • $search (string) - Search term(s) to retrieve matching discounts for. This searches the "name", "description", and "code" columns. Default empty.

Return values:

  • (array) An array of RCP_Discount objects if results are found. Empty array if no results are found.

Introduced: Version 3.3.

Examples:

Retrieve up to 100 active discount codes.

$discounts = rcp_get_discounts( array(
	'status' => 'active',
	'number' => 100
) );

Retrieve the ID numbers of discounts that expire between January 1st, 2000, and December 31st of the current year.

$discounts = rcp_get_discounts( array(
	'expiration_query' => array(
		'after'     => '2000-01-01 00:00:00',
		'before'    => date( 'Y-12-31 23:59:59' ),
		'inclusive' => true
	),
	'fields' => 'id'
) );
Have more questions? Submit a request
Powered by Zendesk