Я хочу, чтобы всплывающее сообщение появлялось, когда пользователь без определенного почтового индекса пытается просмотреть определенную категорию.
Я получил возможность перенаправить пользователя, если почтовый индекс отсутствует Разрешенный массив.
Я бы просто хотел заявить "Вы не можете получить доступ к этой категории" и без какого-либо перенаправления.
function my_restrict_access() {
if ( is_product_category() ) {
$category = get_queried_object();
if ( $category ) {
$category_id = $category->term_id;
$allowed_category_id = array(3078, 3385);
if ( in_array($category_id, $allowed_category_id) ) {
if ( !is_user_logged_in() ) {
wp_redirect( '/' );
exit;
} else {
global $woocommerce;
$customer = new WC_Customer();
$customer_postcode = $woocommerce->customer->get_billing_postcode();
// uncomment line below for debug purposes, this will show you the postcode on the current page
//echo $customer_postcode;
$allowed_post_code = array(3610, 3626, 3650);
if ( !in_array($customer_postcode, $allowed_post_code) ) {
wp_redirect( '/' );
exit;
}
}
}
}
}
}
add_action( 'template_redirect', 'my_restrict_access');