Restrict Content Pro

RCP_Discount

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/

The RCP_Discount class was released in version 3.3. It contains information about a single discount and provides helper methods for interacting with the discount.

Getting a discount

The main way to retrieve a discount object is with the rcp_get_discount() function. This requires that you know the discount ID number. Here’s an example:

$discount = rcp_get_discount( 123 );

You can also use rcp_get_discount_by() to retrieve a single discount by one of its values, such as the discount name or code. Example:

$discount = rcp_get_discount_by( 'code', 'beta_tester' );

Alternatively, some of our other helper functions will return RCP_Discount objects automatically, including:

Do not create a new instance of the RCP_Discount class manually.

Retrieving discount data

Once you have an RCP_Discount object, you can use it to retrieve all the information about the discount. Here’s a list of methods:

  • get_id()
  • get_name()
  • get_description()
  • get_amount()
  • get_unit()
  • get_code()
  • get_use_count()
  • get_max_uses()
  • get_status()
  • get_expiration()
  • get_membership_level_ids()
  • is_one_time()
  • is_valid()

get_id()

Returns the ID number of the discount.

get_name()

Returns the name of the discount.

get_description()

Returns the description of the discount.

get_amount()

Returns the discount amount.

get_unit()

Returns the discount unit. This will either be % or flat.

get_code()

Returns the discount code.

get_use_count()

Returns the number of times the discount has been used.

get_max_uses()

Returns the maximum number of times the discount may be used. Returns 0 if there is no limit.

get_status()

Returns the status of the discount code. Will return either active or disabled.

get_expiration()

Returns the date the discount expires, or an empty string if there is no expiration date.

get_membership_level_ids()

Returns an array of membership level IDs that the discount code can be used on. Returns an empty array if the discount can be used on any membership level.

is_one_time()

Returns true if this is a one-time discount, or false if it’s a recurring discount.

is_valid( $membership_level_id = 0 )

Determines whether or not a discount code is valid for use, and may be used with the supplied membership level ID. This method returns true if all the following conditions are met:

  • The discount status is active.
  • The expiration date is either not configured or is in the future.
  • The maximum number of uses has not been exceeded.
  • The provided membership level ID is in the allowed list of levels (or the discount is set up to allow any level).

Other helper methods

  • increment_use_count() â€” Increase the use count by one.
  • decrement_use_count() â€” Decrease the use count by one.
  • is_expired() â€” Returns true if the discount has an expiration date set and that date is in the past.
  • is_maxed_out() â€” Returns true if the discount has a maximum number of uses set and that limit has been reached.
  • has_membership_level_ids() â€” Returns true if the discount is locked to one or more membership levels.
  • store_for_user( $user_id ) â€” Stores this discount code in a user’s history (rcp_user_discounts meta).
  • remove_from_user( $user_id ) â€” Removes this discount code from a user’s history.
Last updated: September 11, 2026
Was this page helpful?
Thanks for the feedback!