{"id":1286,"date":"2022-11-03T10:57:31","date_gmt":"2022-11-03T10:57:31","guid":{"rendered":"https:\/\/mklasen.com\/?p=1286"},"modified":"2022-11-03T11:04:33","modified_gmt":"2022-11-03T11:04:33","slug":"rename-coupon-code-text-to-discount-code-in-woocommerce","status":"publish","type":"post","link":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/","title":{"rendered":"Rename Coupon code text to Discount code in Woocommerce"},"content":{"rendered":"\n

Another day, another snippet! This snippet allows you to replace all occurrences of the coupon word to something that you like better, like “discount code”.<\/p>\n\n\n\n

This code is highly inspired from the code shared in WPBeaches’ blog post<\/a>. It’s customized for usage in classes, and optimized as some occurrences were not replaced and the “Click here to enter your code” was broken. I shared these optimizations here as I was not able to comment on the blog post. <\/p>\n\n\n\n

The hooks, and filters we’re using<\/h2>\n\n\n\n
add_filter( 'gettext', array( $this, 'rename_coupon_field_on_cart' ), 10, 3 );\nadd_filter( 'woocommerce_coupon_error', array( $this, 'rename_coupon_label' ), 10, 3 );\nadd_filter( 'woocommerce_coupon_message', array( $this, 'rename_coupon_label' ), 10, 3 );\nadd_filter( 'woocommerce_cart_totals_coupon_label', array( $this, 'rename_coupon_label' ), 10, 1 );\nadd_filter( 'woocommerce_checkout_coupon_message', array( $this, 'rename_coupon_message_on_checkout' ) );<\/code><\/pre>\n\n\n\n

The functions<\/h2>\n\n\n\n

And these are the attached functions, mind that this code belongs in a class. A full code sample is shown in the bottom of this post.<\/p>\n\n\n\n

public function rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {\n\tif ( is_admin() || 'woocommerce' !== $text_domain ) {\n\t\treturn $translated_text;\n\t}\n\tif ( 'Coupon:' === $text ) {\n\t\t$translated_text = 'Discount Code:';\n\t}\n\n\tif ( 'Coupon has been removed.' === $text ) {\n\t\t$translated_text = 'Discount code has been removed.';\n\t}\n\n\tif ( 'Apply coupon' === $text ) {\n\t\t$translated_text = 'Apply';\n\t}\n\n\tif ( 'Coupon code' === $text ) {\n\t\t$translated_text = 'Discount Code';\n\n\t}\n\n\tif ( 'If you have a coupon code, please apply it below.' === $text ) {\n\t\t$translated_text = 'If you have a discount code, please apply it below.';\n\t}\n\n\treturn $translated_text;\n}\n\npublic function rename_coupon_message_on_checkout( $text ) {\n\treturn 'Have a discount code?' . ' ' . __( 'Click here to enter your code', 'woocommerce' ) . '<\/a>';\n}\n\n\npublic function rename_coupon_label( $err, $err_code = null, $something = null ) {\n\t$err = str_ireplace( 'Coupon', 'Discount Code ', $err );\n\treturn $err;\n}<\/code><\/pre>\n\n\n\n

Full code sample<\/h2>\n\n\n\n
init();\n\t}\n\n\tpublic function init() {\n\n\t\tadd_filter( 'gettext', array( $this, 'rename_coupon_field_on_cart' ), 10, 3 );\n\t\tadd_filter( 'woocommerce_coupon_error', array( $this, 'rename_coupon_label' ), 10, 3 );\n\t\tadd_filter( 'woocommerce_coupon_message', array( $this, 'rename_coupon_label' ), 10, 3 );\n\t\tadd_filter( 'woocommerce_cart_totals_coupon_label', array( $this, 'rename_coupon_label' ), 10, 1 );\n\t\tadd_filter( 'woocommerce_checkout_coupon_message', array( $this, 'rename_coupon_message_on_checkout' ) );\n\t}\n\n\tpublic function rename_coupon_field_on_cart( $translated_text, $text, $text_domain ) {\n\t\tif ( is_admin() || 'woocommerce' !== $text_domain ) {\n\t\t\treturn $translated_text;\n\t\t}\n\t\tif ( 'Coupon:' === $text ) {\n\t\t\t$translated_text = 'Discount Code:';\n\t\t}\n\n\t\tif ( 'Coupon has been removed.' === $text ) {\n\t\t\t$translated_text = 'Discount code has been removed.';\n\t\t}\n\n\t\tif ( 'Apply coupon' === $text ) {\n\t\t\t$translated_text = 'Apply';\n\t\t}\n\n\t\tif ( 'Coupon code' === $text ) {\n\t\t\t$translated_text = 'Discount Code';\n\n\t\t}\n\n\t\tif ( 'If you have a coupon code, please apply it below.' === $text ) {\n\t\t\t$translated_text = 'If you have a discount code, please apply it below.';\n\t\t}\n\n\t\treturn $translated_text;\n\t}\n\n\tpublic function rename_coupon_message_on_checkout( $text ) {\n\t\treturn 'Have a discount code?' . ' ' . __( 'Click here to enter your code', 'woocommerce' ) . '<\/a>';\n\t}\n\n\n\tpublic function rename_coupon_label( $err, $err_code = null, $something = null ) {\n\t\t$err = str_ireplace( 'Coupon', 'Discount Code ', $err );\n\t\treturn $err;\n\t}\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

Another day, another snippet! This snippet allows you to replace all occurrences of the coupon word to something that you like better, like “discount code”. This code is highly inspired from the code shared in WPBeaches’ blog post. It’s customized for usage in classes, and optimized as some occurrences were not replaced and the “Click […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[1],"tags":[],"acf":[],"yoast_head":"\nRename Coupon code text to Discount code in Woocommerce - Marinus Klasen<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\" \/>\n<meta property=\"og:locale\" content=\"nl_NL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Rename Coupon code text to Discount code in Woocommerce - Marinus Klasen\" \/>\n<meta property=\"og:description\" content=\"Another day, another snippet! This snippet allows you to replace all occurrences of the coupon word to something that you like better, like “discount code”. This code is highly inspired from the code shared in WPBeaches’ blog post. It’s customized for usage in classes, and optimized as some occurrences were not replaced and the “Click […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\" \/>\n<meta property=\"og:site_name\" content=\"Marinus Klasen\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/marinus.klasen\" \/>\n<meta property=\"article:author\" content=\"http:\/\/facebook.com\/marinus.klasen\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-03T10:57:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-03T11:04:33+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/mklasen.com\/content\/uploads\/2020\/03\/cropped-cropped-mklasen-logo-margin-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinus Klasen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/marinusklasen\" \/>\n<meta name=\"twitter:site\" content=\"@marinusklasen\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinus Klasen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\"},\"author\":{\"name\":\"Marinus Klasen\",\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\"},\"headline\":\"Rename Coupon code text to Discount code in Woocommerce\",\"datePublished\":\"2022-11-03T10:57:31+00:00\",\"dateModified\":\"2022-11-03T11:04:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\"},\"wordCount\":126,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\"},\"articleSection\":[\"General\"],\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\",\"url\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\",\"name\":\"Rename Coupon code text to Discount code in Woocommerce - Marinus Klasen\",\"isPartOf\":{\"@id\":\"https:\/\/mklasen.com\/#website\"},\"datePublished\":\"2022-11-03T10:57:31+00:00\",\"dateModified\":\"2022-11-03T11:04:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#breadcrumb\"},\"inLanguage\":\"nl-NL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/mklasen.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"General\",\"item\":\"https:\/\/mklasen.com\/general\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Rename Coupon code text to Discount code in Woocommerce\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/mklasen.com\/#website\",\"url\":\"https:\/\/mklasen.com\/\",\"name\":\"Marinus Klasen\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/mklasen.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"nl-NL\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29\",\"name\":\"Marinus Klasen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"nl-NL\",\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg\",\"contentUrl\":\"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg\",\"width\":1500,\"height\":1000,\"caption\":\"Marinus Klasen\"},\"logo\":{\"@id\":\"https:\/\/mklasen.com\/#\/schema\/person\/image\/\"},\"description\":\"Marinus has been working in software\/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge. Marinus Klasen on Twitter\",\"sameAs\":[\"http:\/\/facebook.com\/marinus.klasen\",\"https:\/\/nl.linkedin.com\/in\/marinusklasen\",\"https:\/\/twitter.com\/http:\/\/twitter.com\/marinusklasen\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Rename Coupon code text to Discount code in Woocommerce - Marinus Klasen","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/","og_locale":"nl_NL","og_type":"article","og_title":"Rename Coupon code text to Discount code in Woocommerce - Marinus Klasen","og_description":"Another day, another snippet! This snippet allows you to replace all occurrences of the coupon word to something that you like better, like “discount code”. This code is highly inspired from the code shared in WPBeaches’ blog post. It’s customized for usage in classes, and optimized as some occurrences were not replaced and the “Click […]","og_url":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/","og_site_name":"Marinus Klasen","article_publisher":"http:\/\/facebook.com\/marinus.klasen","article_author":"http:\/\/facebook.com\/marinus.klasen","article_published_time":"2022-11-03T10:57:31+00:00","article_modified_time":"2022-11-03T11:04:33+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/mklasen.com\/content\/uploads\/2020\/03\/cropped-cropped-mklasen-logo-margin-1.png","type":"image\/png"}],"author":"Marinus Klasen","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/marinusklasen","twitter_site":"@marinusklasen","twitter_misc":{"Written by":"Marinus Klasen","Est. reading time":"3 minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#article","isPartOf":{"@id":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/"},"author":{"name":"Marinus Klasen","@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29"},"headline":"Rename Coupon code text to Discount code in Woocommerce","datePublished":"2022-11-03T10:57:31+00:00","dateModified":"2022-11-03T11:04:33+00:00","mainEntityOfPage":{"@id":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/"},"wordCount":126,"commentCount":2,"publisher":{"@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29"},"articleSection":["General"],"inLanguage":"nl-NL","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/","url":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/","name":"Rename Coupon code text to Discount code in Woocommerce - Marinus Klasen","isPartOf":{"@id":"https:\/\/mklasen.com\/#website"},"datePublished":"2022-11-03T10:57:31+00:00","dateModified":"2022-11-03T11:04:33+00:00","breadcrumb":{"@id":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#breadcrumb"},"inLanguage":"nl-NL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/mklasen.com\/rename-coupon-code-text-to-discount-code-in-woocommerce\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/mklasen.com\/"},{"@type":"ListItem","position":2,"name":"General","item":"https:\/\/mklasen.com\/general\/"},{"@type":"ListItem","position":3,"name":"Rename Coupon code text to Discount code in Woocommerce"}]},{"@type":"WebSite","@id":"https:\/\/mklasen.com\/#website","url":"https:\/\/mklasen.com\/","name":"Marinus Klasen","description":"","publisher":{"@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/mklasen.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"nl-NL"},{"@type":["Person","Organization"],"@id":"https:\/\/mklasen.com\/#\/schema\/person\/bbad02776afb72dfba2ebfe1956a4e29","name":"Marinus Klasen","image":{"@type":"ImageObject","inLanguage":"nl-NL","@id":"https:\/\/mklasen.com\/#\/schema\/person\/image\/","url":"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg","contentUrl":"https:\/\/mklasen.com\/content\/uploads\/2021\/01\/DONE1171.jpg","width":1500,"height":1000,"caption":"Marinus Klasen"},"logo":{"@id":"https:\/\/mklasen.com\/#\/schema\/person\/image\/"},"description":"Marinus has been working in software\/web development for more than a decade. Since 2020 his attention shifted on sharing knowledge and developing products and tools for sharing knowledge. Marinus Klasen on Twitter","sameAs":["http:\/\/facebook.com\/marinus.klasen","https:\/\/nl.linkedin.com\/in\/marinusklasen","https:\/\/twitter.com\/http:\/\/twitter.com\/marinusklasen"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"Marinus Klasen","author_link":"https:\/\/mklasen.com\/author\/mklasen\/"},"_links":{"self":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts\/1286"}],"collection":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/comments?post=1286"}],"version-history":[{"count":2,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts\/1286\/revisions"}],"predecessor-version":[{"id":1289,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/posts\/1286\/revisions\/1289"}],"wp:attachment":[{"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/media?parent=1286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/categories?post=1286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mklasen.com\/wp-json\/wp\/v2\/tags?post=1286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}