Change coupon error message using functions.php
-
I’ve researched on woocommerce forums and docs, but only found a snippet that didn’t make any sense for what I’m trying to do.
I would like to change one of the coupon error messages by adding some code to the theme’s functions.php file.
The code I found on their forums is this:
add_action( 'init', 'woocommerce_custom_message' ); function woocommerce_custom_message() { global $woocommerce; $woocommerce->add_message( 'My Message' ); $woocommerce->add_error( 'An Error Message' ); }
But that code doesn’t mention any way to target a specific error message. In the core woocommerce files, there’s a file named ‘class-wc-coupon.php’ which has code in it pertaining to that message, which reads like this (only posting the one message here, not all):
public function get_coupon_error( $err_code ) { switch ( $err_code ) { case self::E_WC_COUPON_MIN_SPEND_LIMIT_NOT_MET: $err = sprintf( __( 'The minimum spend for this coupon is %s.', 'woocommerce' ), woocommerce_price( $this->minimum_amount ) ); break; default: $err = ''; break; } return apply_filters( 'woocommerce_coupon_error', $err, $err_code, $this );
Does anyone have any idea how to format this for the functions.php file so it overrides the core? I don’t want to have to update the core file every time the plugin is updated, if possible.
Thanks!
- The topic ‘Change coupon error message using functions.php’ is closed to new replies.