将经常性总运输标签更改为不包括 "FREE"

Change Recurring Total Shipping Label to not include "FREE"

我很难找到任何基于 WooCommerce 订阅插件的文档来调整运输标签名称。

I would like to remove the word: FREE at the end.

我试过使用另一个 Stack Overflow 用户的这个函数,但它似乎甚至没有在 'cart' 中触发:

/**
 * Remove shipping name from the label in Cart and Checkout pages
 */
function sticky_wc_cart_totals_shipping_method_label( $method ) {
    $label = $method->get_label();

    if ( $method->cost > 0 ) {
        if ( WC()->cart->tax_display_cart == 'excl' ) {
            $label .= ': ' . wc_price( $method->cost );
            if ( $method->get_shipping_tax() > 0 && WC()->cart->prices_include_tax ) {
                $label .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
            }
        } else {
            $label .= ': ' . wc_price( $method->cost + $method->get_shipping_tax() );
            if ( $method->get_shipping_tax() > 0 && ! WC()->cart->prices_include_tax ) {
                $label .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
            }
        }
    }

    return apply_filters( 'woocommerce_cart_shipping_method_full_label', $label, $method );
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'sticky_wc_cart_totals_shipping_method_label', 10, 2 );

我不知道这是否仅适用于购物车总计,而不是经常性总运费。

对此有什么想法吗?

我找到了解决办法。下载订阅插件后,我找到了与之关联的代码。所以我创建了这个过滤器并且似乎工作得很好。

/**
 * Remove shipping pricing from the label in Cart and Checkout pages
 */
add_filter( 'wcs_cart_totals_shipping_method', 'wcs_method_label', 10, 2 );
function wcs_method_label($method, $cart) {
    return $cart->label;
}