我想更改购物车中的删除优惠券链接。目前,括号中是“删除”一词:[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 );
) 的表格单元格中,而不是显示在带有折扣金额的单元格中,那就太好了。但现在如果我能在第一步中更改链接,那确实会有帮助。
最佳答案
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/