免费送货标签的 WooCommerce 自定义功能 [英] WooCommerce custom function for Free Shipping Label
本文介绍了免费送货标签的 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 commerce,那么以下过滤器将对您有所帮助.
if you are using latest woo commerce then following filter will be helpful to you.
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;
}
这篇关于免费送货标签的 WooCommerce 自定义功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文