您可以試試這段代碼,它會限制其他用戶在您的網站上購買。它只會允許您的電子郵件ID列表上的客戶購買,
add_action('woocommerce_after_checkout_validation' , 'add_user_email_restriction', 10, 2);
function add_user_email_restriction($data, $errors) {
$valid_emails = get_available_email_addresses();
// should be in array format
if(isset($data[ 'billing_email' ]) && !empty($data[ 'billing_email' ])) {
if(!in_array($data[ 'billing_email' ], $valid_emails)) {
$errors->add('email', __('You are not allowed to purchase.', 'text-domain'));
}
}
}
function get_available_email_addresses() {
return array('[email protected]','[email protected]');
}
我該如何設置以上代碼只有一個特定的產品? – Ketan
在這種情況下,您必須提取購物車內容,並檢查購物車中是否有特定產品,以及是否允許其他產品。 –
感謝。問題已修復。 – Ketan