1

I need to change the default coupon label that WooCommerce is adding to the cart and checkout table.

This can be done with:

add_filter( 'woocommerce_cart_totals_coupon_label', 'my_function', 99, 2 );

function my_function( $label, $coupon ) {
    return 'Discount'; 
}

But I need different names for the coupons. I need coupon 1 to be 'Discount', and all other coupons should be displayed as 'Coupon' (without the actual coupon name), like in this image.

7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
sarah579
  • 35
  • 4

1 Answers1

2

You can use $coupon->get_code() to get the coupon code from the coupon object, which is passed as the 2nd argument to the callback function.

So you get:

function filter_woocommerce_cart_totals_coupon_label( $label, $coupon ) {
    // Compare
    if ( $coupon->get_code() == 'coupon 1' ) {
        $label = __( 'Discount', 'woocommerce' );       
    } else {
        $label = __( 'Coupon', 'woocommerce' );
    }
    
    return $label;
}
add_filter( 'woocommerce_cart_totals_coupon_label', 'filter_woocommerce_cart_totals_coupon_label', 10, 2 );
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50