在 WooCommerce 结帐中将“[删除]”链接文本更改为优惠券图标

问题描述

我想将“[删除]”链接文本更改为 WooCommerce 结帐页面中的优惠券图标。

我希望它是来自 Font Awesome 的垃圾桶图标,而不是“[Remove]”。

我找到了 2 个代码片段来更改文本:

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 &amp; Re-Calculate]','woocommerce' ) . '</a>';

    return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html','filter_woocommerce_cart_totals_coupon_html',10,3 );

function filter_woocommerce_cart_totals_coupon_html( $coupon_html,$discount_amount_html ) {
    // Change text
    $coupon_html = str_replace( '[Remove]','[Remove &amp; Re-Calculate]',$coupon_html );

    return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html',3 );

这些代码片段允许我更改文本,但我不知道如何添加图标。如果有人能帮助我,我将不胜感激..

解决方法

例如,您可以在第二个代码段中使用以下内容添加 Font Awesome Icon

function filter_woocommerce_cart_totals_coupon_html( $coupon_html,$coupon,$discount_amount_html ) {
    // Change returned text
    return str_replace( '[Remove]',' [<i class="fas fa-minus-circle"></i> Remove &amp; Re-Calculate]',$coupon_html );
}
add_filter( 'woocommerce_cart_totals_coupon_html','filter_woocommerce_cart_totals_coupon_html',10,3 );

代码位于活动子主题(或活动主题)的functions.php 文件中。它应该可以工作。

您将进入结帐页面,例如:

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...