I need to re-direct customers from Germany to a custom page if they try to access a product page and I've started to put something together, but I don't know how to finish it.
Here's what I got:
add_action( 'do not know which hook to use', 'geo_origin_redirect' );
function geo_origin_redirect() {
$location = WC_Geolocation::geolocate_ip();
$country = $location['country'];
$product_ids = array( 10, 20, 30 );
$product_categories = array( 'makeup' );
$redirection = false;
// what to do here to make it check the product?
if( in_array( $???->get_product_id(), $product_ids ) || has_term( $product_categories, 'product_cat', $???->get_product_id() ) ) {
$redirection = true;
break;
}
}
if( $redirection && $country === 'Germany' ){
wp_redirect( home_url( '/your-page/' ) );
exit;
}
}
Any help is appreciated.