In a recent update to WooCommerce, they have changed the word Discounts to Coupon(s). This is in the order total table. See this screenshot for > clarity https://prnt.sc/sq6xfh
I would like to change this back to Discounts wherever possible as it doesn't really make sense to say Coupons when you have actually applied a discount. Ideally, it would be great to show a Discounts and a Coupon(s) row if required as sometimes you may apply a coupon AND a discount.
For now, I am I trying to change the Discount(s) label as pointed out above in the screenshot.
I have found the code in the plugins core files and know I cannot change that, this is the code:
</tr>
<?php if ( 0 < $order->get_total_discount() ) : ?>
<tr>
<td class="label"><?php esc_html_e( 'Coupon(s):', 'woocommerce' ); ?></td>
<td width="1%"></td>
<td class="total">-
<?php echo wc_price( $order->get_total_discount(), array( 'currency' => $order->get_currency() ) ); // WPCS: XSS ok. ?>
</td>
</tr>
<?php endif; ?>
I am not sure how to change Coupon(s) to Discounts in the code above via my functions.php
Any help appreciated. Cheers Nik
You can use the WordPress gettext
hook this way:
add_filter('gettext', 'custom_strings_translation', 20, 3);
function custom_strings_translation( $translated_text, $text, $domain ) {
global $pagenow, $typenow;
// Settings
$current_text = "Coupon(s):";
$new_text = "Discount(s):";
// Targeting admin single order pages
if( is_admin() && in_array($pagenow, ['post.php', 'post-new.php']) && 'shop_order' === $typenow && $current_text === $text ){
$translated_text = __( $new_text, $domain );
}
return $translated_text;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related answers: