Replace Woocommerce coupon amount line by a custom string Replace Woocommerce coupon amount line by a custom string wordpress wordpress

Replace Woocommerce coupon amount line by a custom string


You need to use woocommerce_cart_totals_coupon_html filter hook like in this example:

add_filter( 'woocommerce_cart_totals_coupon_html', 'custom_cart_totals_coupon_html', 30, 3 );function custom_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {    // For percent coupon types only    if( 'percent' == $coupon->get_discount_type() ){        $percent              = $coupon->get_amount(); // Get the coupon percentage number        $discount_amount_html = '<span>' . $percent . ' % </span>'; // Formatting  percentage        // Replacing coupon discount, by custom percentage        $coupon_html          = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', urlencode( $coupon->get_code() ), defined( 'WOOCOMMERCE_CHECKOUT' ) ? wc_get_checkout_url() : wc_get_cart_url() ) ) . '" class="woocommerce-remove-coupon" data-coupon="' . esc_attr( $coupon->get_code() ) . '">' . __( '[Remove]', 'woocommerce' ) . '</a>';    }    return $coupon_html;}

Code goes in function.php file of the active child theme (or active theme). Tested and works.

enter image description here

It will replace the discounted amount by the coupon percentage on cart and checkout pages…