我希望删除购物车和 checkout 页面中的发货标签值时,将该值分配给发货.例:-将"统一税率100.00美元"改为"100.00美元".这意味着我只需要不带标签文本的值.你能帮我做到这一点吗?
我在shipping_package_rates_filter_callback函数中更改为$rates[$targeted_rate_id]->label = '';
.但它仍然在值的开头显示':'(冒号符号).例:-:100.00$.
shipping_package_rates_filter_callback个
add_filter( 'woocommerce_package_rates', 'shipping_package_rates_filter_callback', 100, 2 );
function shipping_package_rates_filter_callback( $rates, $package ) {
// HERE define your targeted rate id
$targeted_rate_id = 'flat_rate:4';
if ( ! array_key_exists($targeted_rate_id, $rates) )
return $rates;
$new_cost = WC()->session->get('shipping_cost'); // Get new cost from WC sessions
if ( ! empty($new_cost) ) {
// Set shipping label empty
$rates[$targeted_rate_id]->label = '';
$rate = $rates[$targeted_rate_id];
$cost = $rate->cost; // Set the initial cost in a variable for taxes calculations
$rates[$targeted_rate_id]->cost = $new_cost; // Set the new cost
$has_taxes = false; // Initializing
$taxes = array(); // Initializing
foreach ($rate->taxes as $key => $tax_cost){
if( $tax_cost > 0 ) {
$tax_rate = $tax_cost / $cost; // Get the tax rate conversion
$taxes[$key] = $new_cost * $tax_rate; // Set the new tax cost in taxes costs array
$has_taxes = true; // There are taxes (set it to true)
}
}
if( $has_taxes ) {
$rates[$targeted_rate_id]->taxes = $taxes; // Set taxes costs array
}
} else {
unset($rates[$targeted_rate_id]);
}
return $rates;
}