add_action('woocommerce_product_query',function($q){if (function_exists('wc_get_customer_default_location')){$location=wc_get_customer_default_location();$country=$location['country'];// If visitor is from Singapore if (strtoupper($country)==='SG'){$tax_query=(array) $q->get('tax_query');$tax_query[]=array('taxonomy'=>'product_tag','field'=>'slug','terms'=>array('singapore'),// only show products tagged "singapore" 'operator'=>'IN');$q->set('tax_query',$tax_query)}}},10,1);// Prevent direct access to hidden products add_action('template_redirect',function(){if (is_product() && function_exists('wc_get_customer_default_location')){$location=wc_get_customer_default_location();$country=$location['country'];if (strtoupper($country)==='SG'){global $post;$tags=wp_get_post_terms($post->ID,'product_tag',array('fields'=>'slugs'));// If product does not have the "singapore" tag,redirect to shop if (! in_array('singapore',$tags,true)){wp_redirect(wc_get_page_permalink('shop'));exit}}}});