WP Manifestindependent plugin directory
manifest / ecommerce / woo-geo-restrict

WooCommerce Geo Restrict

Restrict WooCommerce products by geographic location based on product tags and categories

by MonDB Dev · github.com/mondb-dev/woo-geo-restrict · website

0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/mondb-dev/woo-geo-restrict/archive/refs/heads/main.zip

A WordPress plugin that restricts WooCommerce product visibility based on geographic location using product tags and categories.

Description

WooCommerce Geo Restrict allows you to create access rules that control which products are visible to customers based on their country. This is perfect for:

  • Region-specific product offerings
  • Compliance with regional licensing restrictions
  • International market management
  • Geographic pricing strategies

Features

  • Product-level restrictions - Restrict individual products
  • Category-level restrictions - Restrict entire product categories
  • Tag-level restrictions - Restrict products by tags
  • Two restriction types:
    • Hide from selected countries
    • Show only to selected countries
  • Automatic geolocation - Uses WooCommerce's built-in IP geolocation
  • Multiple fallbacks - Billing address and store country fallbacks
  • Complete product filtering - Works with shop, categories, tags, search, related products, cross-sells, and up-sells
  • Direct access prevention - Returns 404 for restricted products
  • HPOS compatible - Works with WooCommerce High-Performance Order Storage
  • Developer friendly - Includes hooks and filters for customization

Requirements

  • WordPress 5.8 or higher
  • WooCommerce 5.0 or higher
  • PHP 7.4 or higher

Installation

From GitHub

  1. Download the latest release from this repository
  2. Upload the plugin files to /wp-content/plugins/woo-geo-restrict/
  3. Activate the plugin through the 'Plugins' menu in WordPress
  4. Go to WooCommerce → Geo Restrict to configure settings

Manual Installation

  1. Clone this repository:
    git clone https://github.com/mondb-dev/woo-geo-restrict.git
  2. Upload to your WordPress plugins directory
  3. Activate the plugin
  4. Configure settings under WooCommerce → Geo Restrict

Usage

Global Settings

Navigate to WooCommerce → Geo Restrict to configure:

  1. Enable Geo Restrictions - Toggle the plugin on/off
  2. Detection Method - Choose between WooCommerce Geolocation or User Billing Address
  3. Default Action - Set the default behavior for restricted products

Product-Level Restrictions

  1. Edit any product
  2. Find the Geo Restrictions meta box in the sidebar
  3. Check "Enable geo restrictions for this product"
  4. Select restriction type:
    • Hide from selected countries - Product hidden from selected countries
    • Show only to selected countries - Product visible only to selected countries
  5. Select one or more countries (hold Ctrl/Cmd for multiple selection)
  6. Save the product

Category-Level Restrictions

  1. Go to Products → Categories
  2. Add a new category or edit an existing one
  3. Configure geo restriction settings
  4. All products in that category will inherit these restrictions

Tag-Level Restrictions

  1. Go to Products → Tags
  2. Add a new tag or edit an existing one
  3. Configure geo restriction settings
  4. All products with that tag will inherit these restrictions

Restriction Priority

If a product has multiple restrictions (product, category, and tag level), any restriction that applies will hide the product. The checks are performed in this order:

  1. Product-level restrictions
  2. Category-level restrictions
  3. Tag-level restrictions

How It Works

Geolocation Detection

The plugin detects a customer's country using:

  1. WooCommerce Geolocation (Primary) - IP-based detection using WooCommerce's native functionality
  2. User Billing Address (Fallback) - For logged-in users with saved billing information
  3. Store Base Country (Final Fallback) - Uses your WooCommerce store's default country

Product Filtering

Restricted products are automatically:

  • Hidden from shop pages
  • Hidden from category and tag archives
  • Hidden from search results
  • Excluded from related products
  • Excluded from cross-sells and up-sells
  • Blocked from direct access (404 error)

For Developers

Filters

Filter the detected user country:

add_filter( 'wgr_user_country', function( $country ) {
    // Modify detected country
    // For example, force US for testing:
    // return 'US';
    return $country;
} );

Helper Functions

Get user's country:

$country = WGR_Geolocation::get_user_country();

Get all countries:

$countries = WGR_Geolocation::get_countries();

Check if product is restricted:

$is_restricted = WGR_Restrictions::is_product_restricted( $product_id, $country_code );

Standards Compliance

This plugin adheres to:

  • ✅ WordPress Coding Standards
  • ✅ WooCommerce Plugin Standards
  • ✅ WordPress Plugin Handbook guidelines
  • ✅ Security best practices (sanitization, validation, nonces, capability checks)
  • ✅ Internationalization (i18n) ready
  • ✅ HPOS compatibility

File Structure

woo-geo-restrict/
├── woo-geo-restrict.php          # Main plugin file
├── includes/
│   ├── class-wgr-geolocation.php    # Geolocation handler
│   ├── class-wgr-restrictions.php   # Restriction rules handler
│   ├── class-wgr-product-filter.php # Product filtering
│   └── class-wgr-admin.php          # Admin interface
├── readme.txt                     # WordPress.org readme
├── CHANGELOG.md                   # Version history
└── README.md                      # This file

Support

For bug reports, feature requests, or contributions:

License

This plugin is licensed under the GPL v2 or later.

WooCommerce Geo Restrict
Copyright (C) 2024 MonDB Dev

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

Credits

Developed by MonDB Dev

Changelog

See CHANGELOG.md for detailed version history.