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

标签 php wordpress woocommerce cart coupon

我想更改购物车中的删除优惠券链接。目前,括号中是“删除”一词:[Remove]

我在cart-totals.php模板中找到了wc_cart_totals_coupon_html函数。 我还找到了该函数内部的链接。

$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 );) 的表格单元格中,而不是显示在带有折扣金额的单元格中,那就太好了。但现在如果我能在第一步中更改链接,那确实会有帮助。

最佳答案

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

要更改购物车中的表格单元格,您可以编辑 cart/cart-totals.php在线提交35-38

关于php - WooCommerce:更改删除购物车中的优惠券链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63099960/

相关文章:

php - 在 Laravel 中通过路由将变量传递到 Controller 时出现错误

php - 酵母搜索引擎优化 |如何创建自定义变量

php - 在为 wordpress 安装插件时如何避免出现 fatal error ?

php - woocommerce 如何获取单个产品的 $cart_item_key

php - 如何在 Wordpress 导航菜单中自动添加类别和子类别

php - Woocommerce add_to_cart 给我 fatal error

php - 使用 PDO::prepare 创建一个在其 create 语句中有问号的函数?

javascript - 在 PHP 中为 Javascript 生成小而有效的变量名的算法

java - Java 中的动态绑定(bind)

image - wordpress 是否应该通过 https 自动加载图像?