Skip to content
Docs
Get RestroPress

Filter

rpress_api_discounts

Updated
On this page

Filters the discount list returned by the discounts API endpoint.

Runs at the end of RPRESS_API::get_discounts() after the discount list has been built. The array is keyed by 'discounts' and holds one entry per discount with fields such as amount, type, uses, status and requirements. Use it to expose extra discount data or remove entries.

Parameters#

ParameterTypeDescription
$discount_listarrayDiscount data keyed by 'discounts'.
$thisRPRESS_APIThe API instance handling the request.

Return value#

array. The discount list to return.

Example#

function my_api_discounts( $discount_list, $api ) {
	if ( isset( $discount_list['discounts'] ) ) {
		$discount_list['total_discounts'] = count( $discount_list['discounts'] );
	}
	return $discount_list;
}
add_filter( 'rpress_api_discounts', 'my_api_discounts', 10, 2 );

Notes#

Not applied when the requested discount is not found; the error array is returned directly.

Source#

Applied in:

  • includes/api/class-rpress-api.php (line 1293), in RPRESS_API::get_discounts()
Was this page helpful?