Ejemplo n.º 1
0
function rcp_validate_discount_with_ajax()
{
    if (isset($_POST['code'])) {
        $return = array();
        $return['valid'] = false;
        $return['full'] = false;
        $subscription_id = isset($_POST['subscription_id']) ? absint($_POST['subscription_id']) : 0;
        rcp_setup_registration($subscription_id, $_POST['code']);
        if (rcp_validate_discount($_POST['code'], $subscription_id)) {
            $code_details = rcp_get_discount_details_by_code(sanitize_text_field($_POST['code']));
            if (!rcp_registration_is_recurring() && rcp_get_registration()->get_recurring_total() == 0.0 && rcp_get_registration()->get_total() == 0.0) {
                // this is a 100% discount
                $return['full'] = true;
            }
            $return['valid'] = true;
            $return['amount'] = rcp_discount_sign_filter($code_details->amount, $code_details->unit);
        }
        wp_send_json($return);
    }
    die;
}
/**
 * Automatically setup the registration object
 */
function rcp_setup_registration_init()
{
    if (empty($_POST['rcp_level'])) {
        return;
    }
    $level_id = abs($_POST['rcp_level']);
    $discount = empty($_POST['rcp_discount']) ? null : sanitize_text_field($_POST['rcp_discount']);
    rcp_setup_registration($level_id, $discount);
}