0
我正在設計在wordpress中使用woocommerce插件的在線產品商店。但現在我想確定客戶只能在上午9點到下午12點之間訂購產品,晚上4點到8點之間訂購產品,所以我該怎麼做?如何讓特定的時間在線商店?
我正在設計在wordpress中使用woocommerce插件的在線產品商店。但現在我想確定客戶只能在上午9點到下午12點之間訂購產品,晚上4點到8點之間訂購產品,所以我該怎麼做?如何讓特定的時間在線商店?
許多解決方案,您可以禁用網關,以便客戶可以不買(然後更改默認的消息)
add_filter('woocommerce_payment_gateways', 'disable_gateway_time', 99, 1);
function custom_gateway($gateways){
$current_time = date('H');
// If ok return $gateways
if (($current_time > 9 && $current_time < 12) || ($current_time > 16 && $current_time < 18))
return $gateways;
// Else return empty array
return array();
}
或者你也可以使用另一個鉤子,以顯示錯誤消息(if語句可以簡化)
add_action('woocommerce_checkout_process', 'custom_checkout_process' , 99);
function my_custom_checkout_field_process() {
// You can make your own control here
$current_time = date('H');
if (! (($current_time > 9 || $current_time < 12) && ($current_time > 16 || $current_time < 18)))
wc_add_notice(__('The store is closed'), 'error');
}
不要忘了檢查你的php ini時區或者你可以添加date()函數之前。
date_default_timezone_set('Europe/Paris');
這對[wordpress.se]來說是一個更好的問題。 – 2014-11-23 16:07:29