Created
February 8, 2014 16:09
-
-
Save cklosowski/8885994 to your computer and use it in GitHub Desktop.
Overview of error message improvements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Example of adding an error to the edd_set_error | |
/** | |
* Checks whether a discount code is active. | |
* | |
* @since 1.0 | |
* @param int $code_id | |
* @return bool | |
*/ | |
function edd_is_discount_active( $code_id = null ) { | |
$discount = edd_get_discount( $code_id ); | |
$return = false; | |
if ( $discount ) { | |
if ( $discount->post_status == 'active' && ! edd_is_discount_expired( $code_id ) ) { | |
$return = true; | |
} else { | |
edd_set_error( 'edd-discount-error', __( 'This discount is not active.', 'edd' ) ); | |
} | |
} | |
return apply_filters( 'edd_is_discount_active', $return, $code_id ); | |
} | |
// In the ajax-functions.php, instead of just returning the generic message if the response is false we use this | |
$errors = edd_get_errors(); | |
$return['msg'] = $errors['edd-discount-error']; | |
edd_unset_error( 'edd-discount-error' ); // This helps with the UX when trying multiple codes | |
// For the display, it was as simple as adding a line after the discount code input | |
// Display none since we don't need it yet, ID for targeting (better performance) and class for stlye (repeatable) | |
<input class="edd-input" type="text" id="edd-discount" name="edd-discount" placeholder="<?php _e( 'Enter discount', 'edd' ); ?>"/> | |
<span id="edd-discount-error-wrap" class="edd-discount-error" style="display:none;"></span> | |
// In the edd-checkout-global.js we make an addition to reset that span | |
$('#edd-discount-error-wrap').html('').hide(); | |
// And then 1 modification to what we're putting into the span (instead of the alert()) | |
$('#edd-discount-error-wrap').html(discount_response.msg).show(); | |
// and in the edd.css under the 'Checkout Fields' section, a HUGE addition | |
.edd-discount-error { color: #F33; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment