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 is part of the developer docs and is considered custom code. Unfortunately, we cannot provide support for custom code at this time as we do not have the additional resources that would be necessary to provide support for custom code.
If you need assistance with this, please reach out to our list of consultants for further assistance: 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 (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'
) );