woocommerce在特定日期和截止时间的运费选项



我有三个运费,

  • 星期六交货- flat_rate:34 -£11.25
  • 周六送货- flat_rate:35 -订单=> 75英镑时为5英镑
  • 免费次日达- shipping_method_0_free_shipping19

每周免费次日达。

我希望flat_rate:34在周四(全天)和周五可见,并且只在周五12:30之前可用,之后是"截止"。利率是隐藏的。若订单总金额=>$ 75.00则flat_rate:35可用,_rate:34隐藏。

我希望这个选项与标准的第二天免费送货并列,目前如果订单总额为=>只有free_shipping选项显示…我想要那个和星期六选项(rate:35)显示。

我如何扩展下面的代码来实现上面的目标?

在某个地方我要包括这个

( WC()->cart->subtotal => $threshold ) 

add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_time', 10, 2 );
function hide_shipping_method_based_on_time( $rates, $package )
{
date_default_timezone_set('Europe/London');
$threshold = 75;
$shipping_rate_id_1 = 'flat_rate:34';
$shipping_rate_id_2 = 'flat_rate:35';
// disabled on Mon/Tue/Wed/Sat/Sun 
if ( array_key_exists( $shipping_rate_id_1, $shipping_rate_id_2, $rates ) 
&& ( in_array(date('N'), [1,2,3,6,7]) ) ) {
unset( $rates[$shipping_rate_id_1] );
unset( $rates[$shipping_rate_id_2] );
}
// Cut off 12:30 on Friday's
if ( array_key_exists( $shipping_rate_id_1, $shipping_rate_id_2, $rates ) date('N') = 5 && date('H') => 12:30 ) {
unset($rates[$shipping_rate_id_1]); // remove it
unset($rates[$shipping_rate_id_2]); // remove it
}
return $rates; 
}
<?php
add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_time', 10, 2 );
function hide_shipping_method_based_on_time( $rates, $package )
{
date_default_timezone_set('Europe/London');
$threshold = 75;
$shipping_rate_id_1 = 'flat_rate:34';
$shipping_rate_id_2 = 'flat_rate:35';
$free_shipping_id = 'shipping_method_0_free_shipping19';
$cart_total = WC()->cart->subtotal;
// Disable on Mon/Tue/Wed/Sat/Sun
if ( array_key_exists( $shipping_rate_id_1, $shipping_rate_id_2, $rates ) && ( in_array(date('N'), [1,2,3,6,7]) ) ) {
unset( $rates[$shipping_rate_id_1] );
unset( $rates[$shipping_rate_id_2] );
}

// Cut off 12:30 on Friday's
if ( array_key_exists( $shipping_rate_id_1, $shipping_rate_id_2, $rates ) date('N') = 5 && date('H') => 12:30 ) {
unset($rates[$shipping_rate_id_1]); // remove it
unset($rates[$shipping_rate_id_2]); // remove it
}

// Show flat_rate:35 if cart total is >= £75
if ( $cart_total >= $threshold && array_key_exists( $shipping_rate_id_2, $rates ) ) {
unset( $rates[$shipping_rate_id_1] );
}
// Show both free_shipping and flat_rate:35 if cart total is >= £75
if ( $cart_total >= $threshold && array_key_exists( $free_shipping_id, $rates ) ) {
$rates[$shipping_rate_id_2]->cost = 0;
}
return $rates; 
}

查看

如果有变化,请在评论中告诉我

最新更新