要显示航运成本,当运费等于零时,我使用以下代码(因为woocommerce隐藏了运送方法的零成本)
add_filter( 'woocommerce_cart_shipping_method_full_label', 'custom_add_zero_cost_to_shipping_label', 10, 2 );
function custom_add_zero_cost_to_shipping_label( $label, $method ) {
// if shipping rate is 0, concatenate ": $0.00" to the label
if ( ! ( $method->cost > 0 ) ) {
$label .= ': ' . wc_price(0);
}
// return original or edited shipping label
return $label;
}如何更改此代码以显示“免费”而不是显示$0,00 (零成本)?
如果对下面的代码进行修改,这是可能的吗?
发布于 2020-11-17 18:31:22
如果相关送货方法的成本为零(免费送货除外),则只需使用以下将“免费”附加到送货方法标签的内容
add_filter( 'woocommerce_cart_shipping_method_full_label', 'Add_free_to_shipping_label_for_zero_cost', 10, 2 );
function Add_free_to_shipping_label_for_zero_cost( $label, $method ) {
// If shipping method cost is 0 or null, display 'Free' (except for free shipping method)
if ( ! ( $method->cost > 0 ) && $method->method_id !== 'free_shipping' ) {
$label .= ': ' . __('Free');
}
return $label;
}代码位于活动子主题(或活动主题)的functions.php文件中。测试和工作。
https://stackoverflow.com/questions/64878670
复制相似问题