Skip to content
Docs
Get RestroPress

Filter

rpress_ajax_discount_response

Updated
On this page

Filters the JSON response for the AJAX discount code request.

Runs in the apply_discount AJAX handler after the code has been validated and, if valid, applied to the cart. On success the array contains msg ('valid'), discount_value, amount, total_plain, total, code and html; on failure it holds msg with the error text. The filtered value is output with wp_json_encode().

Parameters#

ParameterTypeDescription
$returnarrayResponse data for the discount request.

Return value#

array. The response array to encode as JSON.

Example#

function my_discount_response( $return ) {
	if ( isset( $return['msg'] ) && 'valid' === $return['msg'] ) {
		$return['thanks'] = __( 'Discount applied!', 'my-plugin' );
	}
	return $return;
}
add_filter( 'rpress_ajax_discount_response', 'my_discount_response' );

Source#

Applied in:

  • includes/class-rpress-ajax.php (line 1407), in RP_AJAX::apply_discount()

See also#

Was this page helpful?