AI Verified

Name

Transforming Coupon Codes into Discount Codes in WooCommerce

About

In certain situations, the term "coupon" may be inappropriate. To address this, we've developed several guides suggesting alternative synonyms for "coupon." This specific guide focuses on replacing the term "coupon" with the more widely used "discount." Unfortunately, the process of changing "coupon code" to "discount code" is not as straightforward.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Simply copy the pre-coded solution to your active child theme’s functions.php or preferably the Code Snippets Plugin.

Codevault

WDXTechnologies

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

29/11/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Transforming Coupon Codes into Discount Codes in WooCommerce

 
                    
1/**
2* Snippet Name: Transforming Coupon Codes into Discount Codes in WooCommerce.
3* Snippet Author: wdxtechnologies.com
4*/
5 
6add_filter( 'gettext', 'ecommercehints_rename_coupon_field_on_cart', 10, 3 );
7add_filter( 'woocommerce_coupon_error', 'ecommercehints_rename_coupon_label', 10, 3 );
8add_filter( 'woocommerce_coupon_message', 'ecommercehints_rename_coupon_label', 10, 3 );
9add_filter( 'woocommerce_cart_totals_coupon_label', 'ecommercehints_rename_coupon_label',10, 1 );
10add_filter( 'woocommerce_checkout_coupon_message', 'ecommercehints_rename_coupon_message_on_checkout' );
11add_filter( 'gettext', 'woocommerce_change_coupon_field_instruction_text' );
12 
13function ecommercehints_rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {
14if ( is_admin() || 'woocommerce' !== $text_domain ) {
15return $translated_text;
16}
17if ( 'Coupon:' === $text ) {
18$translated_text = 'Discount Code:';
19}
20if ('Coupon has been removed.' === $text){
21$translated_text = 'Discount code has been removed.';
22}
23if ( 'Apply coupon' === $text ) {
24$translated_text = 'Apply Code';
25}
26if ( 'Coupon code' === $text ) {
27$translated_text = 'Discount Code';
28}
29return $translated_text;
30}
31 
32function ecommercehints_rename_coupon_message_on_checkout() {
33return 'Have a discount code? <a href="#" class="showcoupon">Enter it here</a>';
34}
35function woocommerce_change_coupon_field_instruction_text($translated) {
36$translated = str_ireplace('If you have a coupon code, please apply it below.', '', $translated);
37return $translated;
38}
39function ecommercehints_rename_coupon_label( $err, $err_code=null, $something=null ){
40$err = str_ireplace("Coupon","Discount ",$err);
41return $err;
42}

0

Related Snippets

Please see some snippets below related to this snippet..

WooCommerce

AI Verified

5

WooCommerce Show Number Of Units Sold On Product Page

Added: 1 year ago

Last Updated: 2 months ago

Showing the number of product units sold on the single product page is a great way to introduce Fear Of Missing Out (FOMO). You can highlight how many products are sold to let customers know a product...

WooCommerce

AI Verified

0

Disable Woocommerce Analytics & other bloat

Added: 2 years ago

Last Updated: 1 year ago

WooCommerce

AI Verified

1

WooCommerce Logout Redirect

Added: 1 year ago

Last Updated: 2 months ago

This guide shows you how you can redirect users to any page on your site when they logout instead of the default My Account login page. Simply enter the Post ID of the URL you wish to redirect users t...

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WooCommerce

AI Verified

0

Show 'NEW' Badges for Recently Added Items in WooCommerce

Added: 8 months ago

Last Updated: 8 months ago

This code snippet adds a "NEW!" badge to products in WooCommerce, indicating that they are newly added. The badge is displayed both on the product archive pages and the single product template for a s...

WooCommerce

AI Verified

0

Integrate a 'Sold' Column into the WordPress Dashboard's Product Section

Added: 10 months ago

Last Updated: 10 months ago

Are you interested in knowing the quantity of items you have sold?

WooCommerce

AI Verified

0

Transforming Coupon Codes into Discount Codes in WooCommerce

Added: 9 months ago

Last Updated: 9 months ago

In certain situations, the term "coupon" may be inappropriate. To address this, we've developed several guides suggesting alternative synonyms for "coupon." This specific guide focuses on replacing th...