You can use the following code snippets in your child theme’s functions.php file:
Redirect the 404 error page
Below is the code snippet for insert redirect to a new page instead of the 404 error page when you Completely hide the products from your store..
Customize the Cart/Checkout Restriction Message
Use this code snippet to customize the message when a product is removed from cart due to country restriction.