这里是Woocommerce/wordpress的全新体验。在购物车页面mydomain.local/cart
上,我应该使用什么过滤器在某些时间显示/隐藏统一运费运输方法。在admin中,我设法添加了一个额外的统一费率方法,并将其命名为“第二天”。现在我只想在下午4点之前演示一下统一费率法。我在functions.php上试过
add_filter( 'woocommerce_package_rates', 'custom_change_shipping', 10);
function custom_change_shipping($rates) {
var_dump($rates);
}
似乎什么都没有改变,而且我似乎不能调试$rates
变量,因为当var_dump($rates);
时没有输出任何内容。我尝试了匿名和管理员身份,但似乎都不起作用。
发布于 2018-01-04 17:47:26
感谢@LoicTheAztec确认我是否使用了正确的过滤器。我的另一个问题是我不能在/cart
页面上输出var_dump
。
我发现我需要清除我的“购物车缓存”,进入woocommerce->settings->shipping,在该区域中,禁用,然后再次启用,然后单击保存更改。通过这样做,我可以看到来自var_dump
的输出。
发布于 2018-07-10 02:57:35
由@LoicTheAztec发布的过滤器(应@robert的请求)
add_filter( 'woocommerce_package_rates', 'custom_hide_shipping', 100 );
function custom_hide_shipping( $rates ) {
$current_time = date_i18n(('H'), current_time('timestamp')); //Uses Timezone Settings > General
$maximum_time = array (
'time' =>'16'); //4PM
if ($current_time >= $maximum['time']){
unset( $rates['flat_rate:X'] ); // change X to your rate id
}
return $rates;
}
https://stackoverflow.com/questions/48085777
复制相似问题