Restrict Content Pro
rcp_get_discounts()
Coming soon: Restrict Content Pro is becoming Kadence Memberships. You may see both names used while we update the product, documentation, and customer experience.
Note: This content is provided as a resource within our developer documentation. Because custom code requires highly specific implementation, we encourage you to work with a qualified developer if you need guidance. You can find our recommended consultants here: https://codeable.io/developers/restrict-content-pro/
Serves as a 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 (percentageorflat).$code(string) — Filter by discount code.$status(string) — Filter by discount status (activeordisabled).$one_time(int) — Set to1to only retrieve one-time discounts. Set to0to 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 ofRCP_Discountobjects. Default false.$fields(array) — Array of fields to return. Accepts any known column names or empty to returnRCP_Discountobjects. 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. Acceptsid,name,code,use_count,max_uses,status,expiration,date_created, anddate_modified. Defaultid.$order(string) — How to order results. AcceptsASCandDESC. DefaultDESC.$search(string) — Search term(s) to retrieve matching discounts for. This searches thename,description, andcodecolumns. 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'
) );