Rename the Coupon Code Text in Woocommerce

I recently needed to replace the Coupon Code wording in a Woocommerce store, from “Insert  your Coupon Code” to “Insert your Membership Code”. I used some code posted on Grahame Thomson’s blog, but there was an error that prevented it from working on the Checkout page. I sought help from our developer, and here is the corrected code that worked on our application. The correction was in the function woocommerce_rename_coupon_message_on_checkout. Here is the code that worked.

 

/**
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );
add_filter( 'gettext', 'woocommerce_rename_coupon_field_on_cart', 10, 3 );
add_filter('woocommerce_coupon_error', 'rename_coupon_label', 10, 3);
add_filter('woocommerce_coupon_message', 'rename_coupon_label', 10, 3);
add_filter('woocommerce_cart_totals_coupon_label', 'rename_coupon_label',10, 1);
add_filter( 'woocommerce_checkout_coupon_message', 'woocommerce_rename_coupon_message_on_checkout' );


function woocommerce_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
	// bail if not modifying frontend woocommerce text
	if ( is_admin() || 'woocommerce' !== $text_domain ) {
		return $translated_text;
	}
	if ( 'Coupon:' === $text ) {
		$translated_text = 'Membership Discount Code:';
	}

	if ('Coupon has been removed.' === $text){
		$translated_text = 'Membership discount code has been removed.';
	}

	if ( 'Apply coupon' === $text ) {
		$translated_text = 'Apply Membership Discount Code';
	}

	if ( 'Coupon code' === $text ) {
		$translated_text = 'Membership Discount Code';
	
	} 

	return $translated_text;
}


// rename the "Have a Coupon?" message on the checkout page
function woocommerce_rename_coupon_message_on_checkout() {
	return 'Have a Membership Discount Code?' . ' <a href="#" class="showcoupon">' . __( 'Click here to enter your code', 'woocommerce' ) . '</a>';
}


function rename_coupon_label($err, $err_code=null, $something=null){

	$err = str_ireplace("Coupon","Membership Discount Code ",$err);

	return $err;
}
 */

Feature image photo by Safar Safarov on Unsplash

Related Posts

Leave a Reply

  Subscribe  
Notify of