Woocommerce - 按日期过滤运费

时间:2016-11-24 14:20:33

标签: php wordpress woocommerce

我试图在工作日隐藏特定的购物价格,并且仅在周末(确切地说是星期五晚上)提供。我有5个价格,我想首先显示前3个(按id),并且仅在星期五下午和晚上显示4和5。

 add_filter( 'woocommerce_package_rates', 'hide_friday_special_shipping_method', 10, 2 );

    function hide_friday_special_shipping_method ( $rates, $package ) {

             if ( date("N")==5 && date("G")>=15 || date("N")==6 && date("G")<=8) {


            foreach ( $rates as $rate_id => $rate ) {
            if ( '5' === $rate->method_id ) {
            $free[ $rate_id ] = $rate;
            break;
        }
    }
    return ! empty( $free ) ? $free : $rates;
               = array();
  }
foreach ( $rates as $rate_id => $rate ) {
            if ( '4' === $rate->method_id ) {
            $free[ $rate_id ] = $rate;
            break;
        }
    }
    return ! empty( $free ) ? $free : $rates;
               = array();
  }
  return $rates;
}

它不会返回任何东西。你能告诉我应该怎么做吗?

function hide_friday_special_shipping_method ( $rates ) {

    if ( date("N")==4 && date("G")>=1 || date("N")==6 && date("G")<=8) {

            $rates = unset($rates[3]);
            $rates = unset($rates[4]);

  }
  return $rates;
}

print_r($rates);

试过这个,但它也不起作用..

0 个答案:

没有答案
相关问题