Instead of [Remove
] on the WooCommerce checkout for added coupons, I would like the text to be [Remove & Re-Calculate
].
I am using the following and the text is changed but there is no link (the coupon cannot be removed).
This is what I tried:
add_filter( 'woocommerce_cart_totals_coupon_html', 'change_wc_coupon_removal_text', 10, 3 ); function change_wc_coupon_removal_text( $coupon_html, $coupon, $discount_amount_html ) { $coupon_html = $discount_amount_html . '<br>' . 'Remove & Re-Calculate'; return $coupon_html; }
Advertisement
Answer
includes/wc-cart-functions.php contains at line 293, just before the woocommerce_cart_totals_coupon_html
filter hook.
$coupon_html = $discount_amount_html . ' <a href="' . esc_url( add_query_arg( 'remove_coupon', rawurlencode( $coupon->get_code() ), Constants::is_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>';
So to replace the text, use:
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 );