如何重新安排 WooCommerce 中运输信息的显示。目前,当应用免费送货时,它在购物车和结帐部分中都会显示为“免费送货”。我想修改此显示,以便“免运费”显示在左侧,而在右侧,它表示节省的金额,表示为“节省的 X $”。如何在
cart_totals
和 woocommerce-checkout-review-order-table
部分中实现这一目标?
您可以使用 woocommerce_package_rates 过滤器来实现此目的
/**
* Hide shipping rates when free shipping is available.
* Change the Free Shipping label to 'Saved X'
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
// here you set the saved amount
$saved_amount = 10;
foreach ( $rates as $rate_id => $rate ) {
if ( 'free_shipping' === $rate->method_id ) {
$free[ $rate_id ] = $rate;
$free[ $rate_id ]->label = sprintf("Saved %d",strip_tags( wc_price( $saved_amount ) ));
break;
}
}
return ! empty( $free ) ? $free : $rates;
}
add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );