在Woocommerce中,我正在尝试在购物车和结帐页面上添加估计的交货日范围。 我设置了2个运输区:德国和其他欧洲国家(德国境外)称为“DHL欧洲”。我需要为德国航运国家显示与其他欧洲航运国家不同的交货日范围:
我的代码尝试:
function sv_shipping_method_estimate_label( $label, $method ) {
$label .= '<br /><small class="subtotal-tax">';
switch ( $method->method_id ) {
case 'flat_rate':
$label .= 'Lieferzeit 3-5 Werktage';
break;
case 'free_shipping':
$label .= 'Lieferzeit 3-5 Werktage';
break;
case 'international_delivery':
$label .= 'Lieferzeit 5-7 Werktage';
}
$label .= '</small>';
return $label;
}
add_filter( 'woocommerce_cart_shipping_method_full_label', 'sv_shipping_method_estimate_label', 10, 2 );
它适用于free_shipping
和flat_rate
运输方式,但不适用于欧洲交货(德国境外)。
我究竟做错了什么? 如何为欧洲国家(德国以外)显示正确的日期范围?
您并不需要定位您的送货方式,而是客户送货国家/地区:
add_filter( 'woocommerce_cart_shipping_method_full_label', 'cart_shipping_method_full_label_filter', 10, 2 );
function cart_shipping_method_full_label_filter( $label, $method ) {
// The targeted country code
$targeted_country_code = 'DE';
if( WC()->customer->get_shipping_country() !== $targeted_country_code ){
$days_range = '5-7'; // International
} else {
$days_range = '3-5'; // Germany
}
return $label . '<br /><small class="subtotal-tax">' . sprintf( __("Lieferzeit %s Werktage"), $days_range ) . '</small>';
}
代码在您的活动子主题(或活动主题)的function.php文件中。经过测试和工作。