Restrict Content Pro

RCP_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/

RCP_Discounts

This class was deprecated in Restrict Content Pro 3.3. For new code, use rcp_get_discounts().

RCP_Discounts class allows you to interact with the discounts database table.

get_discounts( $args = array() )

Retrieve discounts from the database. You can filter by discount status like so:

$discounts_db = new RCP_Discounts();
$discounts    = $discounts_db->get_discounts( array( 'status' => 'active' ) );

get_discount( $discount_id = 0 )

Retrieve a specific discount from the database by its ID number. This returns the object from the database like so:

stdClass Object
(
    [id]              => 7
    [name]            => 10% off
    [description]     =>
    [amount]          => 10
    [unit]            => %
    [code]            => 10percent
    [use_count]       => 7
    [max_uses]        => 0
    [status]          => active
    [expiration]      =>
    [subscription_id] => 0
)

get_by( $field = ‘code’, $value = ” )

Retrieve a specific discount code from the database by a field. You can use this to get a discount by its code rather than ID number. Example:

$discounts_db = new RCP_Discounts();
$discount = $discounts_db->get_by( 'code', 'half_off' );

insert( $args = array() )

Used for inserting a new discount into the database. Available arguments are:

  • name (string) – Name of the discount code.
  • description (string) – Discount description.
  • amount (float) – Amount the discount is for.
  • status (string) – Either active or inactive. Default is inactive.
  • unit (string) – Either flat or %. Default is %.
  • code (string) – Discount code.
  • expiration (string) – Date the discount expires in Y-m-d format. Default is empty string (no expiration).
  • max_uses (int) – Maximum number of uses. Use 0 for unlimited.
  • use_count (int) – Number of times the code has been used. Default is 0.
  • subscription_id (int) – Associated subscription ID. Default is 0 (no association).

update( $discount_id = 0, $args = array() )

Update an existing discount code in the database. Arguments are the same as insert().

Additional helper methods:

  • get_status( $discount_id = 0 ) â€” Status of a discount.
  • get_amount( $discount_id = 0 ) â€” Discounted amount.
  • get_uses( $discount_id = 0 ) â€” Times the discount has been used.
  • get_max_uses( $discount_id = 0 ) â€” Maximum uses.
  • get_subscription_id( $discount_id = 0 ) â€” Associated membership level.
  • has_subscription_id( $discount_id = 0 ) â€” Whether a membership level is attached.
  • increase_uses( $discount_id = 0 ) â€” Increase the use count by one.
  • get_expiration( $discount_id = 0 ) â€” Expiration date.
  • get_type( $discount_id = 0 ) â€” flat or %.
  • delete( $discount_id = 0 ) â€” Delete the discount.
  • is_maxed_out( $discount_id = 0 ) â€” Whether max uses are reached.
  • is_expired( $discount_id = 0 ) â€” Whether the code is expired.
  • add_to_user( $user_id = 0, $discount_code = '' ) â€” Add a code to a user’s history.
  • user_has_used( $user_id = 0, $discount_code = '' ) â€” Whether the user has used the code.
  • format_discount( $amount = '', $type = '' ) â€” Prefix % for percentage discounts, or add the currency sign for flat rates.
  • calc_discounted_price( $base_price = '', $discount_amount = '', $type = '%' ) â€” Calculate the discounted price from a base price, amount, and type (% or flat).

Last updated: September 11, 2026
Was this page helpful?
Thanks for the feedback!