php – 免费送货标签的WooCommerce自定义功能

当我将以下内容放入我的functions.PHP时,它会崩溃我的整个网站.
这个功能的目的是改变
elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( '**Free**','woocommerce' ) . ')';

对…

elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( '**To Be Calculated**','woocommerce' ) . ')';

当我更改原始woocommerce / includes / wc-cart-functions.PHP中的一个单词时,它可以完美地运行.我不希望它被更新覆盖.

/**
* Get a shipping methods full label including price
* @param  object $method
* @return string
*/
function wc_cart_totals_shipping_method_label( $method ) {
$label = $method->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>' . 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>' . WC()->countries->inc_tax_or_vat() . '</small>';
        }
    }
} elseif ( $method->id !== 'free_shipping' ) {
    $label .= ' (' . __( 'To Be Calculated','woocommerce' ) . ')';
}

return apply_filters( 'woocommerce_cart_shipping_method_full_label',$label,$method );
}
如果您正在使用最新的woo商业,那么关注过滤器将对您有所帮助.
add_filter( 'woocommerce_cart_shipping_method_full_label','remove_local_pickup_free_label',10,2 );
function remove_local_pickup_free_label($full_label,$method){
    $full_label = str_replace("(Free)","(TBD)",$full_label);
return $full_label;
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...