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

问题描述 投票:0回答:2

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

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

我找到了 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, $coupon, $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', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );

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

php wordpress woocommerce checkout coupon
2个回答
2
投票

例如,您可以在第二个代码片段中使用以下内容添加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 文件中。应该可以。

您将进入结账页面,如下所示:


0
投票

2023 年 9 月,此功能对我有用。它只是用垃圾桶图标替换文本:

function filter_woocommerce_cart_totals_coupon_html( $coupon_html, $coupon, $discount_amount_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() ) . '">' . __( '<i class="fa-solid fa-trash-can"></i>', 'woocommerce' ) . '</a>';

    return $coupon_html;
}
add_filter( 'woocommerce_cart_totals_coupon_html', 'filter_woocommerce_cart_totals_coupon_html', 10, 3 );
© www.soinside.com 2019 - 2024. All rights reserved.