skip to Main Content

I want to change the remove coupon link in the cart. At the moment it’s the word Remove in brackets: [Remove].

I found the function wc_cart_totals_coupon_html in the cart-totals.php template.
And I also found the link inside that function.

$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]', 'woocommerce' ) . '</a>';

I just don’t know how to change that link part.

It would be really great if the link would appear in the table cell with the label (wc_cart_totals_coupon_label( $coupon );) instead the cell with the discount amount. But for now it would really help if I could change the link in a first step.

2

Answers


    1. Try with static url link as per your need.

    2. Create code as per the WooCommerce standard.

    Login or Signup to reply.
  1. wc-cart-functions.php contains on line 295

    echo wp_kses( apply_filters( 'woocommerce_cart_totals_coupon_html', $coupon_html, $coupon, $discount_amount_html ), array_replace_recursive( wp_kses_allowed_html( 'post' ), array( 'a' => array( 'data-coupon' => true ) ) ) ); // phpcs:ignore PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound
    

    So to change the link you can use

    function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_html ) {
        $coupon_html = $discount_amount_html . '<a href="https://www.stackoverflow.com">My url</a>';
    
        return $coupon_html;
    }
    add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
    

    To change the table cell in cart you can edit the cart/cart-totals.php file on line 35-38

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search