How to Change WooCommerce Coupon Error Messages ?
WooCommerce is a powerful eCommerce platform. In order to change WooCommerce coupon error messages you will need access to the functions. PHP file of your active theme.
If you would like to change the default woocommerce error message that I get when client enters a coupon than you will need to use woocommerce_coupon_error filter. You have to use following code snippet to add custom message.
add_filter( 'woocommerce_coupon_error', 'wp_kama_woocommerce_coupon_error_filter', 10, 3 ); /** * Function for `woocommerce_coupon_error` filter-hook. * * @param $err * @param $err_code * @param $null * * @return */ function wp_kama_woocommerce_coupon_error_filter( $err, $err_code, $null ){ // filter... return $err; }
List of error Codes
The WooCommerce coupons class gets coupon data from storage and checks coupon validity.
E_WC_COUPON_ALREADY_APPLIED = 103 E_WC_COUPON_ALREADY_APPLIED_INDIV_USE_ONLY = 104 E_WC_COUPON_EXCLUDED_CATEGORIES = 114 E_WC_COUPON_EXCLUDED_PRODUCTS = 113 E_WC_COUPON_EXPIRED = 107 E_WC_COUPON_INVALID_FILTERED = 100 E_WC_COUPON_INVALID_REMOVED = 101 E_WC_COUPON_MAX_SPEND_LIMIT_MET = 112 E_WC_COUPON_MIN_SPEND_LIMIT_NOT_MET = 108 E_WC_COUPON_NOT_APPLICABLE = 109 E_WC_COUPON_NOT_EXIST = 105 E_WC_COUPON_NOT_VALID_SALE_ITEMS = 110 E_WC_COUPON_NOT_YOURS_REMOVED = 102 E_WC_COUPON_PLEASE_ENTER = 111 E_WC_COUPON_USAGE_LIMIT_COUPON_STUCK = 115 E_WC_COUPON_USAGE_LIMIT_COUPON_STUCK_GUEST = 116 E_WC_COUPON_USAGE_LIMIT_REACHED = 106 WC_COUPON_REMOVED = 201 WC_COUPON_SUCCESS = 200