# Adding Country Block Code in PrestaShop 1.6
For PrestaShop 1.6, the best place to add country restriction code is in an override of the `Cart` or `Address` class. Here’s how to do it properly:
## Method 1: Using a Module (Recommended)
1. Create a simple module with this structure:
“`
/modules/blockcountry/
blockcountry.php
/override/classes/Cart.php
“`
2. In `blockcountry.php`:
“`php
<?php
if (!defined(‘_PS_VERSION_’))
exit;
class BlockCountry extends Module
{
public function __construct()
{
$this->name = ‘blockcountry’;
$this->tab = ‘front_office_features’;
$this->version = ‘1.0.0’;
$this->author = ‘YourName’;
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l(‘Block Countries’);
$this->description = $this->l(‘Blocks orders from specific countries.’);
}
public function install()
{
return parent::install() && $this->registerHook(‘actionValidateOrderBefore’);
}
}
“`
3. In `/override/classes/Cart.php`:
“`php
<?php
class Cart extends CartCore
{
public function checkDeliveryRestrictions($return_error = false, $id_product = false, $id_address_delivery = false)
{
$result = parent::checkDeliveryRestrictions($return_error, $id_product, $id_address_delivery);
// List of country IDs to block
$blocked_countries = array(1, 2, 3); // Replace with your country IDs
$address = new Address($id_address_delivery ? $id_address_delivery : $this->id_address_delivery);
$country = new Country($address->id_country);
if (in_array($country->id, $blocked_countries)) {
if ($return_error) {
return ‘We do not deliver to your country.’;
}
return false;
}
return $result;
}
}
“`
## Method 2: Direct Override (Without Module)
1. Create or edit this file:
`/override/classes/Cart.php` (same content as above)
2. After adding the file, you must:
– Delete the file `/cache/class_index.php` to force PrestaShop to recognize your override
– Clear your browser cache
## How to Find Country IDs
1. Go to your PrestaShop back office
2. Navigate to **International > Countries**
3. Hover over a country name and look at the URL – the ID will be at the end (e.g., `id_country=1`)
## Important Notes:
– Always back up your site before making changes
– Test with a blocked country to ensure the restriction works
– The error message will appear during checkout when users try to proceed
– Consider adding a more visible notice earlier in the checkout process via a hook
Would you like me to modify this solution for a specific point in the checkout process or add any additional features?