I would like to change the "[Remove]" link text to an icon for coupons in WooCommerce checkout page.
Instead of "[Remove]" I would like it to be a trash can icon from Font Awesome.
I have found 2 code snippets to change the text:
function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
// Change text
$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', rawurlencode( $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 & Re-Calculate]', 'woocommerce' ) . '</a>';
return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
OR
function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
// Change text
$coupon_html = str_replace( '[Remove]', '[Remove & Re-Calculate]', $coupon_html );
return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
These code snippets allow me to change the text but I could not figure out how to add the icon. I would appreciate if someone could help me..
For example, you can add a Font Awesome Icon using the following, on your 2nd code snippet:
function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
// Change returned text
return str_replace( '[Remove]', ' [<i class="fas fa-minus-circle"></i> Remove & Re-Calculate]', $coupon_html );
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
Code goes in functions.php file of the active child theme (or active theme). It should work.
You will get in checkout page something like: