Use returned coupon error message in cart. Closes #1994

This commit is contained in:
Coen Jacobs 2012-12-19 15:57:46 +01:00
parent 314af74f3d
commit 944ea5df3d
2 changed files with 17 additions and 4 deletions

View File

@ -1728,9 +1728,8 @@ class WC_Cart {
if ( $the_coupon->id ) {
// Check it can be used with cart
$return = $the_coupon->is_valid();
if ( ! $return || is_wp_error( $return ) ) {
$woocommerce->add_error( is_wp_error( $return ) ? $return->get_error_message() : __( 'Invalid coupon.', 'woocommerce' ) );
if ( ! $the_coupon->is_valid() ) {
$woocommerce->add_error( $the_coupon->get_error_message() );
return false;
}

View File

@ -65,6 +65,9 @@ class WC_Coupon {
/** @public string How much the coupon is worth. */
public $coupon_amount;
/** @public string Error message. */
public $error_message;
/**
* Coupon constructor. Loads coupon data.
*
@ -195,6 +198,16 @@ class WC_Coupon {
update_post_meta( $this->id, 'usage_count', $this->usage_count );
}
/**
* Returns the error_message string
*
* @access public
* @return string
*/
public function get_error_message() {
return $this->error_message;
}
/**
* is_valid function.
*
@ -316,6 +329,7 @@ class WC_Coupon {
$error = __( 'Invalid coupon', 'woocommerce' );
}
return new WP_Error( 'coupon_error', apply_filters( 'woocommerce_coupon_error', $error, $this ) );
$this->error_message = apply_filters( 'woocommerce_coupon_error', $error, $this );
return false;
}
}