Django-Oscar - Excluding Shipping Countries - Part 9.5

In this part, we will control which countries are available for shipping in Django Oscar.

Quite frequently, stores do not ship to every country. This can happen because of shipping costs, legal restrictions, logistics, taxes, or business decisions.

Django Oscar stores this information in the Country model, using the field is_shipping_country.

 

Disable shipping to specific country

If we want to exclude Portugal from the list of available shipping countries, we can set is_shipping_country to False.

from oscar.core.loading import get_model

Country = get_model("address", "Country")

Country.objects.filter(
    iso_3166_1_a2="PT"
).update(is_shipping_country=False)

This removes Portugal from the countries available for shipping.

 

Allow shipping only to specific countries

Another common scenario is to disable shipping for all countries first, and then enable only the countries we want to support.

In this example, we will allow shipping only to Portugal.

from oscar.core.loading import get_model

Country = get_model("address", "Country")

Country.objects.update(is_shipping_country=False)

Country.objects.filter(
    iso_3166_1_a2="PT"
).update(is_shipping_country=True)

Now Portugal is the only country available for shipping.