| |
| <?php
|
| if ( class_exists( 'WooCommerce' ) ) {
|
|
|
| add_filter( 'gettext', 'rd_wc_generic_coupon_replacement', 20, 3 );
|
| add_filter( 'ngettext', 'rd_wc_generic_coupon_replacement_plural', 20, 5 );
|
|
|
|
|
| add_filter( 'woocommerce_add_notice', 'rd_wc_generic_coupon_replacement_in_notice', 20, 1 );
|
| add_filter( 'woocommerce_add_success', 'rd_wc_generic_coupon_replacement_in_notice', 20, 1 );
|
| add_filter( 'woocommerce_add_error', 'rd_wc_generic_coupon_replacement_in_notice', 20, 1 );
|
|
|
| function rd_wc_apply_coupon_discount_replacements( $text ) {
|
| if ( ! is_string( $text ) || $text === '' ) {
|
| return $text;
|
| }
|
|
|
|
|
| $phrase_replace = array(
|
|
|
| 'COUPON DISCOUNT' => 'DISCOUNT',
|
| 'Coupon discount' => 'Discount',
|
| 'coupon discount' => 'discount',
|
| 'COUPON DISCOUNTS' => 'DISCOUNTS',
|
| 'Coupon discounts' => 'Discounts',
|
| 'coupon discounts' => 'discounts',
|
|
|
|
|
| 'DISCOUNT COUPONS' => 'DISCOUNTS',
|
| 'Discount Coupons' => 'Discounts',
|
| 'Discount coupons' => 'Discounts',
|
| 'discount coupons' => 'discounts',
|
|
|
|
|
| 'DISCOUNT DISCOUNTS' => 'DISCOUNTS',
|
| 'Discount discounts' => 'Discounts',
|
| 'discount discounts' => 'discounts',
|
| );
|
|
|
| $text = str_replace(
|
| array_keys( $phrase_replace ),
|
| array_values( $phrase_replace ),
|
| $text
|
| );
|
|
|
| $search_replace = array(
|
|
|
| 'Have A Promotional Code' => 'Got a Discount Code?',
|
| 'have a promotional code' => 'Got a Discount Code?',
|
| 'HAVE A PROMOTIONAL CODE' => 'Got a Discount Code?',
|
|
|
|
|
| 'COUPON CODE' => 'DISCOUNT CODE',
|
| 'Coupon Code' => 'Discount Code',
|
| 'Coupon code' => 'Discount code',
|
| 'coupon code' => 'discount code',
|
| 'PROMOTIONAL CODE' => 'DISCOUNT CODE',
|
| 'Promotional Code' => 'Discount Code',
|
| 'Promotional code' => 'Discount code',
|
| 'promotional code' => 'discount code',
|
|
|
|
|
| 'COUPONS' => 'DISCOUNTS',
|
| 'Coupons' => 'Discounts',
|
| 'coupons' => 'discounts',
|
|
|
|
|
| 'COUPON' => 'DISCOUNT',
|
| 'Coupon' => 'Discount',
|
| 'coupon' => 'discount',
|
| );
|
|
|
| $text = str_replace(
|
| array_keys( $search_replace ),
|
| array_values( $search_replace ),
|
| $text
|
| );
|
|
|
|
|
| $text = preg_replace( '/\b(Discounts)\s+\1\b/', '$1', $text );
|
| $text = preg_replace( '/\b(discounts)\s+\1\b/', '$1', $text );
|
| $text = preg_replace( '/\b(DISCOUNTS)\s+\1\b/', '$1', $text );
|
|
|
| $text = preg_replace( '/\b(Discount)\s+\1\b/', '$1', $text );
|
| $text = preg_replace( '/\b(discount)\s+\1\b/', '$1', $text );
|
| $text = preg_replace( '/\b(DISCOUNT)\s+\1\b/', '$1', $text );
|
|
|
| return $text;
|
| }
|
|
|
| function rd_wc_generic_coupon_replacement( $translated, $original, $domain ) {
|
| if ( is_admin() ) {
|
| return $translated;
|
| }
|
| return rd_wc_apply_coupon_discount_replacements( $translated );
|
| }
|
|
|
| function rd_wc_generic_coupon_replacement_plural( $translated, $single, $plural, $number, $domain ) {
|
| if ( is_admin() ) {
|
| return $translated;
|
| }
|
| return rd_wc_apply_coupon_discount_replacements( $translated );
|
| }
|
|
|
| function rd_wc_generic_coupon_replacement_in_notice( $message ) {
|
| if ( is_admin() ) {
|
| return $message;
|
| }
|
| return rd_wc_apply_coupon_discount_replacements( $message );
|
| }
|
| }
|
| |
| |
Comments