Function
Discounts functions
On this page
- rpress_add_discount()
- rpress_edit_discount()
- rpress_delete_discount()
- rpress_activate_discount()
- rpress_deactivate_discount()
- rpress_discounts_page()
- rpress_get_discounts()
- rpress_has_active_discounts()
- rpress_get_discount()
- rpress_get_discount_by_code()
- rpress_get_discount_by()
- rpress_store_discount()
- rpress_remove_discount()
- rpress_update_discount_status()
- rpress_discount_exists()
- rpress_is_discount_active()
- rpress_get_discount_code()
- rpress_get_discount_start_date()
- rpress_get_discount_expiration()
- rpress_get_discount_max_uses()
- rpress_get_discount_uses()
- rpress_get_discount_min_price()
- rpress_get_discount_amount()
- rpress_get_discount_type()
- rpress_get_discount_excluded_products()
- rpress_get_discount_excluded_category()
- rpress_get_discount_product_reqs()
- rpress_get_discount_category_reqs()
- rpress_get_discount_product_condition()
- rpress_get_discount_status_label()
- rpress_is_discount_not_global()
- rpress_is_discount_expired()
- rpress_is_discount_started()
- rpress_is_discount_maxed_out()
- rpress_discount_is_min_met()
- rpress_discount_is_single_use()
- rpress_discount_product_reqs_met()
- rpress_discount_categories_reqs_met()
- rpress_is_discount_used()
- rpress_is_discount_valid()
- rpress_get_discount_id_by_code()
- rpress_get_discounted_amount()
- rpress_increase_discount_usage()
- rpress_decrease_discount_usage()
- rpress_format_discount_rate()
- rpress_set_cart_discount()
- rpress_unset_cart_discount()
- rpress_unset_all_cart_discounts()
- rpress_get_cart_discounts()
- rpress_cart_has_discounts()
- rpress_get_cart_discounted_amount()
- rpress_get_cart_item_discount_amount()
- rpress_cart_discounts_html()
- rpress_get_cart_discounts_html()
- rpress_coupon_applied_html()
- rpress_display_cart_discount()
- rpress_remove_cart_discount()
- rpress_maybe_remove_cart_discount()
- rpress_multiple_discounts_allowed()
- rpress_listen_for_cart_discount()
- rpress_apply_preset_discount()
- rpress_discount_status_cleanup()
- rpress_get_discounts_cache()
- rpress_set_discounts_cache()
- rpress_filter_discount_code_cleanup()
- rpress_get_discount_value()
Functions for discount codes: creating, validating, applying and reporting on them.
66 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.
rpress_add_discount()#
Handles the add-discount form submission and stores a new discount code.
Hooked to the rpress_add_discount action. Verifies the rpress-discount-nonce nonce, requires the manage_shop_discounts capability, sanitizes the posted fields, rejects duplicate codes, saves through rpress_store_discount() and redirects with a status query arg.
rpress_add_discount( $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$data | array | Required | Posted form data, including name, code, type, amount and the rpress-discount-nonce and rpress-redirect keys. |
Note: Dies with a 403 when the user lacks the manage_shop_discounts capability.
Internal. Defined in includes/admin/discounts/discount-actions.php, line 21.
rpress_edit_discount()#
Handles the edit-discount form submission and saves changes to an existing discount.
Hooked to the rpress_edit_discount action. Verifies the nonce, requires manage_shop_discounts, sanitizes the posted fields, keeps the current uses count, saves through rpress_store_discount() and redirects.
rpress_edit_discount( $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$data | array | Required | Posted form data, including discount-id, rpress-discount-nonce and rpress-redirect. |
Note: Dies with a 403 when the user lacks the manage_shop_discounts capability.
Internal. Defined in includes/admin/discounts/discount-actions.php, line 90.
rpress_delete_discount()#
Handles the delete link for a discount code.
Hooked to the rpress_delete_discount action. Checks the _wpnonce nonce and the manage_shop_discounts capability, then calls rpress_remove_discount() with the discount request value.
rpress_delete_discount( $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$data | array | Required | Request data with _wpnonce and discount (the discount ID). |
Note: Dies with a 403 when the user lacks the manage_shop_discounts capability.
Internal. Defined in includes/admin/discounts/discount-actions.php, line 145.
rpress_activate_discount()#
Handles the activate link for a discount code.
Hooked to the rpress_activate_discount action. Checks the nonce and the manage_shop_discounts capability, then sets the discount status to active with rpress_update_discount_status().
rpress_activate_discount( $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$data | array | Required | Request data with _wpnonce and discount (the discount ID). |
Note: Dies with a 403 when the user lacks the manage_shop_discounts capability.
Internal. Defined in includes/admin/discounts/discount-actions.php, line 166.
rpress_deactivate_discount()#
Handles the deactivate link for a discount code.
Hooked to the rpress_deactivate_discount action. Checks the nonce and the manage_shop_discounts capability, then sets the discount status to inactive with rpress_update_discount_status().
rpress_deactivate_discount( $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$data | array | Required | Request data with _wpnonce and discount (the discount ID). |
Note: Dies with a 403 when the user lacks the manage_shop_discounts capability.
Internal. Defined in includes/admin/discounts/discount-actions.php, line 187.
rpress_discounts_page()#
Renders the Discounts admin page (list, add and edit screens).
Chooses the add or edit form from the rpress-action query arg, otherwise shows the discount codes list table. Fires rpress_discounts_page_top and rpress_discounts_page_bottom on the list screen.
rpress_discounts_page()
Note: Echoes output instead of returning it.
Internal. Defined in includes/admin/discounts/discount-codes.php, line 20.
rpress_get_discounts()#
Retrieves discount code posts matching the given query arguments.
Wraps get_posts() for the rpress_discount post type, defaulting to 30 posts with active, inactive or expired status. Results are cached per argument set for the request. If nothing is found and s is set, it searches the _rpress_discount_code meta instead.
rpress_get_discounts( $args = array() )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$args | array | array() | Arguments merged over the defaults and passed to get_posts(). |
Returns WP_Post[]|int[]|false: Array of discount posts (or IDs when fields is ids), or false when none are found.
Example
$active = rpress_get_discounts( array( 'post_status' => 'active', 'posts_per_page' => 10 ) );
if ( $active ) {
foreach ( $active as $post ) {
echo esc_html( rpress_get_discount_code( $post->ID ) );
}
}
Note: Returns discount posts, not RPRESS_Discount objects.
Defined in includes/discount-functions.php, line 23.
rpress_has_active_discounts()#
Checks whether at least one discount code is currently active.
Queries up to 100 discounts with active status and returns true as soon as one passes rpress_is_discount_active(), without setting session errors.
rpress_has_active_discounts()
Returns bool: True if an active discount exists.
Defined in includes/discount-functions.php, line 66.
rpress_get_discount()#
Returns the RPRESS_Discount object for a discount ID.
rpress_get_discount( $discount_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$discount_id | int | 0 | Discount ID. |
Returns RPRESS_Discount|false: Discount object, or false if the ID is empty or not found.
Example
$discount = rpress_get_discount( 123 );
if ( $discount ) {
echo esc_html( $discount->code );
}
Defined in includes/discount-functions.php, line 95.
rpress_get_discount_by_code()#
Returns the RPRESS_Discount object for a discount code string.
rpress_get_discount_by_code( $code = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | '' | Discount code. |
Returns RPRESS_Discount|false: Discount object, or false if no discount has that code.
Example
$discount = rpress_get_discount_by_code( 'WELCOME10' );
if ( $discount ) {
echo (float) $discount->amount;
}
Defined in includes/discount-functions.php, line 114.
rpress_get_discount_by()#
Retrieves a discount by its code, ID or name.
Supported fields are code, id and name (case-insensitive). Any other field, or an empty field or value, returns false.
rpress_get_discount_by( $field = '', $value = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$field | string | '' | Field to look up: code, id or name. |
$value | mixed | '' | Value to match against the field. |
Returns RPRESS_Discount|false: Discount object, or false if not found or the field is unsupported.
Example
$discount = rpress_get_discount_by( 'code', 'WELCOME10' );
Defined in includes/discount-functions.php, line 131.
rpress_store_discount()#
Creates a discount code, or updates an existing one when a discount ID is given.
Without $discount_id it adds a new RPRESS_Discount; with one it updates that discount. On success it clears the in-request discounts cache.
rpress_store_discount( $details, $discount_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$details | array | Required | Discount arguments, for example name, code, type, amount and status. |
$discount_id | int|null | null | ID of the discount to update; null to create a new one. |
Returns int|false: Discount ID, or false if a new discount could not be created.
Example
$id = rpress_store_discount( array(
'name' => 'Welcome 10',
'code' => 'WELCOME10',
'type' => 'percent',
'amount' => 10,
'status' => 'active',
) );
Note: Performs no capability or nonce checks.
Defined in includes/discount-functions.php, line 167.
rpress_remove_discount()#
Permanently deletes a discount code.
Fires rpress_pre_delete_discount, deletes the post with wp_delete_post() (force delete), then fires rpress_post_delete_discount.
rpress_remove_discount( $discount_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$discount_id | int | 0 | Discount ID. |
Example
rpress_remove_discount( 123 );
Note: Permanent deletion; performs no capability check.
Defined in includes/discount-functions.php, line 195.
rpress_update_discount_status()#
Changes a discount's status.
rpress_update_discount_status( $code_id = 0, $new_status = 'active' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | 0 | Discount ID. |
$new_status | string | 'active' | New status, such as active or inactive. |
Returns bool: True if the status was updated, false if the discount does not exist or the update failed.
Example
rpress_update_discount_status( 123, 'inactive' );
Defined in includes/discount-functions.php, line 210.
rpress_discount_exists()#
Checks whether a discount with the given ID exists.
rpress_discount_exists( $code_id )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | Required | Discount ID. |
Returns bool: True if the discount exists.
Defined in includes/discount-functions.php, line 227.
rpress_is_discount_active()#
Checks whether a discount is active.
With $update true, an active discount found to be expired is marked expired.
rpress_is_discount_active( $code_id = null, $update = true, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$update | bool | true | Whether to mark the discount expired if it is active but past its expiration. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the discount is active.
Defined in includes/discount-functions.php, line 243.
rpress_get_discount_code()#
Returns the code string of a discount.
rpress_get_discount_code( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns string: Discount code.
Defined in includes/discount-functions.php, line 256.
rpress_get_discount_start_date()#
Returns the start date of a discount.
rpress_get_discount_start_date( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns string: Start date, or an empty string if none is set.
Defined in includes/discount-functions.php, line 269.
rpress_get_discount_expiration()#
Returns the expiration date of a discount.
rpress_get_discount_expiration( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns string: Expiration date, or an empty string if none is set.
Defined in includes/discount-functions.php, line 282.
rpress_get_discount_max_uses()#
Returns the maximum number of times a discount can be used.
rpress_get_discount_max_uses( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns int: Maximum uses; 0 means unlimited.
Defined in includes/discount-functions.php, line 295.
rpress_get_discount_uses()#
Returns how many times a discount has been used.
rpress_get_discount_uses( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns int: Number of uses.
Defined in includes/discount-functions.php, line 308.
rpress_get_discount_min_price()#
Returns the minimum cart amount required for a discount.
rpress_get_discount_min_price( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns float: Minimum order amount.
Defined in includes/discount-functions.php, line 321.
rpress_get_discount_amount()#
Returns the amount of a discount.
rpress_get_discount_amount( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns float: Discount amount; a percentage or a flat amount depending on the type.
Defined in includes/discount-functions.php, line 334.
rpress_get_discount_type()#
Returns the type of a discount.
rpress_get_discount_type( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns string: Discount type, percent or flat.
Defined in includes/discount-functions.php, line 347.
rpress_get_discount_excluded_products()#
Returns the menu item IDs a discount cannot be applied to.
rpress_get_discount_excluded_products( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns array: Excluded menu item IDs.
Defined in includes/discount-functions.php, line 360.
rpress_get_discount_excluded_category()#
Returns the category IDs a discount cannot be applied to.
rpress_get_discount_excluded_category( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns array: Excluded category IDs.
Defined in includes/discount-functions.php, line 373.
rpress_get_discount_product_reqs()#
Returns the menu item IDs required for a discount to apply.
rpress_get_discount_product_reqs( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns array: Required menu item IDs.
Defined in includes/discount-functions.php, line 387.
rpress_get_discount_category_reqs()#
Returns the category IDs required for a discount to apply.
rpress_get_discount_category_reqs( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns array: Required category IDs.
Defined in includes/discount-functions.php, line 400.
rpress_get_discount_product_condition()#
Returns the product condition of a discount.
rpress_get_discount_product_condition( $code_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | 0 | Discount ID. |
Returns string: Condition value stored on the discount (whether all or any required items are needed).
Defined in includes/discount-functions.php, line 414.
rpress_get_discount_status_label()#
Returns the human-readable status label of a discount.
rpress_get_discount_status_label( $code_id = null )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
Returns string: Translated status label.
Defined in includes/discount-functions.php, line 426.
rpress_is_discount_not_global()#
Checks whether a discount applies only to selected menu items instead of the whole cart.
By default a discount applies to every item in the cart. A non-global discount applies only to the items chosen as requirements.
rpress_is_discount_not_global( $code_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | 0 | Discount ID. |
Returns bool: True if the discount is not global.
Defined in includes/discount-functions.php, line 442.
rpress_is_discount_expired()#
Checks whether a discount has passed its expiration date.
With $update true, an active discount found to be expired is marked expired.
rpress_is_discount_expired( $code_id = null, $update = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$update | bool | true | Whether to update the discount status when it has expired. |
Returns bool: True if expired.
Defined in includes/discount-functions.php, line 457.
rpress_is_discount_started()#
Checks whether a discount's start date has been reached.
rpress_is_discount_started( $code_id = null, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the discount has started.
Defined in includes/discount-functions.php, line 471.
rpress_is_discount_maxed_out()#
Checks whether a discount has reached its maximum uses.
rpress_is_discount_maxed_out( $code_id = null, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the discount has reached its limit.
Defined in includes/discount-functions.php, line 485.
rpress_discount_is_min_met()#
Checks whether the cart meets the minimum amount for a discount.
rpress_discount_is_min_met( $code_id = null, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the minimum amount is met.
Defined in includes/discount-functions.php, line 499.
rpress_discount_is_single_use()#
Checks whether a discount is limited to one use per customer.
rpress_discount_is_single_use( $code_id = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | 0 | Discount ID. |
Returns bool: True if single use.
Defined in includes/discount-functions.php, line 512.
rpress_discount_product_reqs_met()#
Checks whether the required menu items are in the cart for a discount.
rpress_discount_product_reqs_met( $code_id = null, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the product requirements are met.
Defined in includes/discount-functions.php, line 526.
rpress_discount_categories_reqs_met()#
Checks whether the required categories are represented in the cart for a discount.
rpress_discount_categories_reqs_met( $code_id = null, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code_id | int | null | Discount ID. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the category requirements are met.
Defined in includes/discount-functions.php, line 540.
rpress_is_discount_used()#
Checks whether a customer has already used a discount.
If $code is null the discount is looked up by that (empty) code, otherwise it is looked up by $code_id. Pass the customer's email or user info in $user.
rpress_is_discount_used( $code = null, $user = '', $code_id = 0, $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string|null | null | Discount code; when not null the lookup uses $code_id instead. |
$user | string | '' | User info, typically the customer email. |
$code_id | int | 0 | Discount ID. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the discount has been used by that user.
Note: The $code and $code_id handling is inverted: a non-null $code makes the function look up by $code_id.
Defined in includes/discount-functions.php, line 557.
rpress_is_discount_valid()#
Checks whether a discount code can be applied to the current cart.
Runs the full validation set on the discount (active, started, not expired, not maxed out, minimum amount, requirements, not already used) and returns the combined result.
rpress_is_discount_valid( $code = '', $user = '', $set_error = true )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | '' | Discount code. |
$user | string | '' | User info, typically the customer email. |
$set_error | bool | true | Whether to store a validation error message in the session when the check fails. |
Returns bool: True if the code is valid.
Example
if ( rpress_is_discount_valid( 'WELCOME10', 'customer@example.com', false ) ) {
rpress_set_cart_discount( 'WELCOME10' );
}
Defined in includes/discount-functions.php, line 576.
rpress_get_discount_id_by_code()#
Returns the discount ID for a code.
rpress_get_discount_id_by_code( $code )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | Required | Discount code. |
Returns int: Discount ID, or a falsy value if the code is not found.
Defined in includes/discount-functions.php, line 589.
rpress_get_discounted_amount()#
Applies a discount code to a price and returns the discounted price.
Flat discounts are subtracted (not below zero); percent discounts reduce the price by that percentage. The result passes through the rpress_discounted_amount filter.
rpress_get_discounted_amount( $code, $base_price )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | Required | Discount code. |
$base_price | string|int|float | Required | Price before discount. |
Returns float: Price after discount.
Example
$discounted = rpress_get_discounted_amount( 'WELCOME10', 25.00 );
Defined in includes/discount-functions.php, line 603.
rpress_increase_discount_usage()#
Increments the use count of a discount code.
rpress_increase_discount_usage( $code )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | Required | Discount code. |
Returns int|false: New use count, or false if the code is not found.
Example
rpress_increase_discount_usage( 'WELCOME10' );
Defined in includes/discount-functions.php, line 616.
rpress_decrease_discount_usage()#
Decrements the use count of a discount code.
rpress_decrease_discount_usage( $code )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | Required | Discount code. |
Returns int|false: New use count, or false if the code is not found.
Example
rpress_decrease_discount_usage( 'WELCOME10' );
Defined in includes/discount-functions.php, line 633.
rpress_format_discount_rate()#
Formats a discount amount for display according to its type.
Returns a formatted currency string for flat discounts and the amount followed by a percent sign for any other type.
rpress_format_discount_rate( $type, $amount )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$type | string | Required | Discount type, flat or percent. |
$amount | string|int|float | Required | Discount amount. |
Returns string: Formatted rate.
Example
echo rpress_format_discount_rate( 'percent', 10 ); // 10%
Defined in includes/discount-functions.php, line 649.
rpress_set_cart_discount()#
Applies a discount code to the cart.
Stores the code in the session cart_discounts value. If multiple discounts are not allowed it replaces any existing one. Fires rpress_cart_discount_set and rpress_cart_discounts_updated. It does not validate the code.
rpress_set_cart_discount( $code = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | '' | Discount code. |
Returns string[]: Active cart discount codes after the change.
Example
if ( rpress_is_discount_valid( 'WELCOME10' ) ) {
rpress_set_cart_discount( 'WELCOME10' );
}
Note: Does not validate the code; call rpress_is_discount_valid() first.
Defined in includes/discount-functions.php, line 663.
rpress_unset_cart_discount()#
Removes a discount code from the cart.
Fires rpress_cart_discount_removed and rpress_cart_discounts_updated. The match is case-insensitive.
rpress_unset_cart_discount( $code = '' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$code | string | '' | Discount code. |
Returns string: Remaining discount codes joined with |, or the original array if the cart had none.
Example
rpress_unset_cart_discount( 'WELCOME10' );
Note: Remaining codes are returned as a pipe-separated string, not an array, and are stored upper-cased.
Defined in includes/discount-functions.php, line 692.
rpress_unset_all_cart_discounts()#
Removes every discount from the cart.
rpress_unset_all_cart_discounts()
Example
rpress_unset_all_cart_discounts();
Defined in includes/discount-functions.php, line 714.
rpress_get_cart_discounts()#
Returns the discount codes currently applied to the cart.
rpress_get_cart_discounts()
Returns array|false: Active discount codes, or false if none.
Example
$codes = rpress_get_cart_discounts();
Defined in includes/discount-functions.php, line 723.
rpress_cart_has_discounts()#
Checks whether the cart has any discount applied.
rpress_cart_has_discounts()
Returns bool: True if a discount is applied.
Defined in includes/discount-functions.php, line 732.
rpress_get_cart_discounted_amount()#
Returns the total discount amount applied to the cart.
The result is filtered by rpress_get_cart_discounted_amount.
rpress_get_cart_discounted_amount( $discounts = false )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$discounts | array|false | false | Discount codes to calculate for; false uses the cart's discounts. |
Returns float: Total discounted amount.
Defined in includes/discount-functions.php, line 744.
rpress_get_cart_item_discount_amount()#
Returns the discount amount for a single cart item.
rpress_get_cart_item_discount_amount( $item = array(), $discount = false )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$item | array | array() | Cart item array with at least an id key. |
$discount | string|false | false | A discount code to test, or false to use the cart's discounts. |
Returns float: Discount amount for the item; 0 if the item array is incomplete.
Defined in includes/discount-functions.php, line 755.
rpress_cart_discounts_html()#
Outputs the HTML for the discounts applied to the cart.
Echoes the result of rpress_get_cart_discounts_html() after filtering it with wp_kses() to only span and anchor tags.
rpress_cart_discounts_html()
Note: Echoes output instead of returning it.
Defined in includes/discount-functions.php, line 765.
rpress_get_cart_discounts_html()#
Builds the HTML for the discounts applied to the cart.
Each discount renders as a labelled line with the cart's discounted amount and a remove link to the checkout. Per-discount HTML passes through rpress_get_cart_discount_html and the combined HTML through rpress_get_cart_discounts_html.
rpress_get_cart_discounts_html( $discounts = false )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$discounts | array|false | false | Discount codes; false uses the cart's discounts. |
Returns string|null: HTML string, or null when there are no discounts.
Defined in includes/discount-functions.php, line 791.
rpress_coupon_applied_html()#
Builds the applied-coupon confirmation markup for the checkout summary.
Returns an icon, the code with the discounted amount, and a Remove link for the first cart discount. The result passes through rpress_coupon_applied_html.
rpress_coupon_applied_html()
Returns string: HTML string, or an empty string when no discount is applied.
Defined in includes/discount-functions.php, line 839.
rpress_display_cart_discount()#
Returns or echoes the formatted cart discount amount.
Delegates to the cart object. The $formatted parameter is not used.
rpress_display_cart_discount( $formatted = false, $echo = false )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$formatted | bool | false | Unused. |
$echo | bool | false | Whether to echo the amount instead of returning it. |
Returns string|false|void: Formatted discount when $echo is false (false if the cart has no discounts); nothing when echoing.
Defined in includes/discount-functions.php, line 870.
rpress_remove_cart_discount()#
Handles the request to remove a discount from the cart and redirects to checkout.
Hooked to the rpress_remove_cart_discount action. Reads discount_id and discount_code from the query string, fires rpress_pre_remove_cart_discount and rpress_post_remove_cart_discount, removes the code and redirects.
rpress_remove_cart_discount()
Internal. Defined in includes/discount-functions.php, line 883.
rpress_maybe_remove_cart_discount()#
Removes cart discounts that are no longer valid after an item is removed from the cart.
Hooked to rpress_post_remove_from_cart. Revalidates each applied discount and removes those that fail.
rpress_maybe_remove_cart_discount( $cart_key = 0 )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$cart_key | int | 0 | Cart key of the removed item; unused. |
Internal. Defined in includes/discount-functions.php, line 902.
rpress_multiple_discounts_allowed()#
Checks whether more than one discount can be applied to an order.
Reads the allow_multiple_discounts setting and filters it with rpress_multiple_discounts_allowed.
rpress_multiple_discounts_allowed()
Returns bool: True if multiple discounts are allowed.
Defined in includes/discount-functions.php, line 920.
rpress_listen_for_cart_discount()#
Stores a discount code from the discount request parameter as the session preset discount.
Hooked to init. The code is stripped to letters, digits, hyphens and underscores. It is applied later by rpress_apply_preset_discount().
rpress_listen_for_cart_discount()
Internal. Defined in includes/discount-functions.php, line 930.
rpress_apply_preset_discount()#
Applies the session preset discount to the cart when it is valid.
Hooked to init at priority 999. Filters the code with rpress_apply_preset_discount, applies it with rpress_set_cart_discount() and clears the preset.
rpress_apply_preset_discount()
Internal. Defined in includes/discount-functions.php, line 945.
rpress_discount_status_cleanup()#
Marks active discounts that are expired or at their maximum uses as inactive.
Checks a limited batch of active discounts per run (25 by default, filterable with rpress_discount_status_cleanup_count) and updates post status and status meta with direct database queries.
rpress_discount_status_cleanup()
Internal. Defined in includes/discount-functions.php, line 964.
rpress_get_discounts_cache()#
Returns cached results of a discounts query for the current request.
The cache is a non-persistent PHP global keyed by a hash of the query arguments.
rpress_get_discounts_cache( $hash )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$hash | string | Required | Hash of the query arguments. |
Returns mixed|false: Cached discounts, or false if not cached.
Internal. Defined in includes/discount-functions.php, line 1075.
rpress_set_discounts_cache()#
Stores discounts query results in the per-request cache.
rpress_set_discounts_cache( $hash, $data )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$hash | string | Required | Hash of the query arguments. |
$data | array | Required | Results to store. |
Internal. Defined in includes/discount-functions.php, line 1093.
rpress_filter_discount_code_cleanup()#
Removes the quotes around the meta value column in the cleanup query SQL.
Used as a posts_request filter during rpress_discount_status_cleanup() so the uses-to-max-uses meta comparison works.
rpress_filter_discount_code_cleanup( $sql )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$sql | string | Required | SQL statement. |
Returns string: Modified SQL.
Internal. Defined in includes/discount-functions.php, line 1107.
rpress_get_discount_value()#
Calculates the discount value of a code against the current cart.
Computes the discount from the cart contents, including add-ons for percent discounts, and passes it through rpress_get_discount_price_value. Returns a formatted currency string by default.
rpress_get_discount_value( $discount, $type = 'currency' )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
$discount | string | Required | Discount code. |
$type | string | 'currency' | Pass currency for a formatted amount; any other value returns the raw number. |
Returns string|float|void: Formatted amount or raw number; nothing if the code is empty.
Example
echo esc_html( rpress_get_discount_value( 'WELCOME10' ) );
Note: Reads the current cart and expects the code to exist.
Defined in includes/discount-functions.php, line 1117.
