为了账号安全,请及时绑定邮箱和手机立即绑定

WooCommerce:更改删除购物车中的优惠券链接

WooCommerce:更改删除购物车中的优惠券链接

PHP
拉莫斯之舞 2023-08-26 17:39:14
我想更改购物车中的删除优惠券链接。目前,括号中是“Remove”一词:[Remove]。wc_cart_totals_coupon_html我在模板中找到了该功能cart-totals.php。我还找到了该函数内部的链接。$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>';我只是不知道如何更改该链接部分。wc_cart_totals_coupon_label( $coupon );如果链接出现在带有标签 ( ) 的表格单元格中,而不是显示在带有折扣金额的单元格中,那就太好了。但就目前而言,如果我能第一步更改链接,那确实会有帮助。
查看完整描述

2 回答

?
慕无忌1623718

TA贡献1744条经验 获得超4个赞

wc-cart-functions.php包含第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

因此,要更改链接,您可以使用


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 );

要更改购物车中的表格单元格,您可以编辑第35-38cart/cart-totals.php行的文件



查看完整回答
反对 回复 2023-08-26
?
FFIVE

TA贡献1797条经验 获得超6个赞

  1. 根据您的需要尝试使用静态 url 链接。

  2. 根据 WooCommerce 标准创建代码。


查看完整回答
反对 回复 2023-08-26
  • 2 回答
  • 0 关注
  • 92 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信