Restrict Payment Methods for PrestaShop
A powerful PrestaShop module that allows you to restrict specific payment methods based on cart content (products, categories, or brands). Perfect for handling special payment restrictions for specific product types, categories, or manufacturers.
✨ Features
- 🔒 Server-Side Payment Filtering - Secure restriction that cannot be bypassed by users
- 🎯 Multiple Restriction Criteria - Filter by product ID, category ID, or brand/manufacturer ID
- 💬 Custom User Messages - Display personalized messages explaining why certain payment methods are unavailable
- 🏪 Multi-Shop Support - Different rules for different shops in multi-shop environments
- ⚡ Performance Optimized - Advanced caching system and optimized database queries (solves N+1 problem)
- 📊 Bulk Actions - Enable, disable, or delete multiple rules at once
- 🔍 AJAX Search - User-friendly admin interface with instant search for products, categories, and brands
- 📝 Activity Logging - Track when and why payment restrictions are applied
- 🌍 Multi-Language Support - Full translation support with PrestaShop 8 XLIFF system
- 🎨 Theme Compatible - Works with most PrestaShop themes (includes multiple fallbacks)
🚀 Why This Module?
Security First
Unlike basic JavaScript-only solutions, this module implements a double-layer protection system:
- Primary Layer: Server-side filtering via <code>paymentOptions</code> hook (cannot be bypassed)
- Secondary Layer: Client-side fallback for older themes + user-friendly messages
Performance Optimized
- 1-hour caching system to minimize database queries
- Bulk SQL queries eliminate the N+1 problem
- Lazy loading of assets (only on checkout pages)
- Database indexes on all search fields
Production Ready
- Tested with PrestaShop 1.7.6+ and 8.x
- Multi-shop and multi-language support
- Automatic cache invalidation on rule changes
- Complete logging system for debugging
- Server-side validation to prevent invalid configurations
📦 Installation
Method 1: Manual Installation
1. Download the latest release from GitHub Releases 2. Upload the <code>restrictpayments</code> folder to <code>/modules</code> directory of your PrestaShop installation 3. Go to Modules > Module Manager in your PrestaShop back office 4. Find "Restrict Payment Methods" and click Install
Method 2: Upload via Back Office
1. Download the module ZIP file 2. Go to Modules > Module Manager 3. Click Upload a Module and select the ZIP file 4. Click Configure after installation
🔧 Configuration
Creating a New Rule
1. Navigate to Payment > Restrict Payments in your PrestaShop back office 2. Click Add New Rule 3. Configure the rule:
Basic Information
- Rule Name: Give your rule a descriptive name (supports multiple languages)
- Custom Message (optional): Message displayed to customers when payment methods are restricted
Restriction Criteria (at least one required)
- Product ID: Restrict payments when a specific product is in cart
- Category ID: Restrict payments when products from a specific category are in cart
- Brand ID: Restrict payments when products from a specific manufacturer/brand are in cart
Payment Methods
- Select which payment methods to restrict when the criteria match
- Multiple payment methods can be selected
Status
- Enabled: Activate or deactivate the rule
4. Click Save
> Note: You must specify at least one criterion (product, category, or brand) and at least one payment method to restrict.
Using the Search Feature
Instead of manually entering IDs, use the built-in search buttons:
- Select Product: Search products by name or reference
- Select Category: Search categories by name
- Select Brand: Search manufacturers/brands by name
💡 Use Cases
Example 1: Restrict Cash on Delivery for Electronics
Rule: "No COD for Electronics"
Category ID: 3 (Electronics) Restricted Methods: Cash on Delivery Custom Message: "Cash on delivery is not available for electronic products."
Example 2: Restrict PayPal for Specific Brand
Rule: "No PayPal for Brand X"
Brand ID: 5 Restricted Methods: PayPal Custom Message: "PayPal payments are not available for this brand."
Example 3: Restrict Multiple Methods for High-Value Products
Rule: "Premium Product Restrictions"
Product ID: 123 Restricted Methods: Cash on Delivery, Check Payment Custom Message: "Only credit card and bank transfer are available for this product."
🏪 Multi-Shop Support
The module fully supports PrestaShop's multi-shop feature:
- Create different restriction rules for different shops
- Rules can be shop-specific or shared across shops
- Each shop maintains its own rule cache for optimal performance
🌍 Multi-Language Support
- Rule names are translatable for each language
- Custom messages can be different for each language
- Admin interface automatically adapts to the current language
- Compatible with PrestaShop 8's modern XLIFF translation system
🔄 Upgrade from Version 1.x
If you're upgrading from version 1.x to 2.0:
- The module will automatically upgrade your database schema
- All existing rules will be preserved
- New features (custom messages, multi-shop support, server-side filtering) will be available immediately
- Clear your browser cache after upgrading
🛠️ Developer Information
Architecture
Hooks Used
- <code>paymentOptions</code> - Server-side payment filtering (main security layer)
- <code>displayPaymentTop</code> - Client-side fallback + user messages
- <code>actionFrontControllerSetMedia</code> - Load frontend assets (checkout only)
- <code>displayBackOfficeHeader</code> - Load admin assets
Database Schema
- <code>ps_restrict_payments_rule</code> - Main rules table
- <code>ps_restrict_payments_rule_lang</code> - Multi-language support
- <code>ps_restrict_payments_rule_shop</code> - Multi-shop associations
Cache Management
The module automatically clears its cache when:
- A rule is created, updated, or deleted
- The module is uninstalled
- Manual: Call <code>$module->clearCache()</code> from code
Performance Features
- Caching: Rules cached with 1-hour TTL
- Bulk Queries: Product categories fetched in single JOIN query
- Lazy Loading: Assets loaded only on checkout pages
- Indexed Database: All search fields properly indexed
File Structure
restrictpayments/
├── restrictpayments.php # Main module class ├── classes/ │ └── RestrictPaymentsRule.php # Model with multishop/multilang ├── controllers/admin/ │ └── AdminRestrictPaymentsController.php # Admin interface ├── sql/ │ ├── install.php # Database installation │ └── uninstall.php # Database cleanup ├── upgrade/ │ └── upgrade-2.0.0.php # Upgrade scripts ├── views/ │ ├── js/ # JavaScript files │ ├── css/ # Stylesheets │ └── templates/ # Smarty templates └── translations/ # XLIFF translation files
🐛 Troubleshooting
Payment methods still appear
1. Verify the rule is enabled (green toggle in the list) 2. Check that product/category/brand IDs are correct 3. Clear PrestaShop cache: Advanced Parameters > Performance > Clear Cache 4. Check logs: Advanced Parameters > Logs
Custom message not showing
1. Ensure you entered a custom message for the current language 2. Verify your theme uses the <code>displayPaymentTop</code> hook 3. Check browser console for JavaScript errors
Multi-shop rules not working
1. Ensure multi-shop is enabled in PrestaShop settings 2. Verify the rule is associated with the correct shop 3. Clear cache for the specific shop context
Performance issues
1. Check if caching is working (enable debug mode to see cache hits) 2. Verify database indexes exist (re-run module installation if needed) 3. Consider reducing the number of active rules if you have many
📋 Requirements
- PrestaShop: 1.7.6.0 or higher (including 8.x)
- PHP: 7.1+ (7.2+ recommended for PrestaShop 8)
- MySQL: 5.6+ or MariaDB 10.0+
- PHP Extensions: mbstring, gd, curl, xml, zip
📄 License
This module is released under the MIT License. See LICENSE file for details.
You are free to:
- ✅ Use commercially
- ✅ Modify
- ✅ Distribute
- ✅ Private use
⚠️ Disclaimer
This module is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement.
Important:
- ✅ Always test in a development/staging environment before production
- ✅ Create a complete backup of your store before installation
- ✅ Verify compatibility with your PrestaShop version and other modules
- ❌ The author is not responsible for any damage, data loss, or issues caused by using this module
Use at your own risk. For production environments, consider using professional installation services.
🐛 Bug Reports & Feature Requests
Found a bug or have a feature request? Please open an issue on GitHub Issues.
When reporting bugs, please include:
- PrestaShop version
- PHP version
- Module version
- Steps to reproduce
- Error messages (if any)
📝 Changelog
See CHANGELOG.md for a detailed version history.
💙 Support This Project
This module is completely free and always will be.
If you're using it in your business and it's saving you development time, please consider supporting its development:
<a href="https://www.paypal.com/paypalme/ettorestani" target="_blank"> <img src="https://img.shields.io/badge/Donate-PayPal-blue.svg? alt="Support via PayPal" height="40"> </a>
Even a small contribution helps me:
- ✅ Keep the module updated with new PrestaShop versions
- ✅ Fix bugs faster
- ✅ Add new features based on community feedback
- ✅ Provide better documentation and support
Thank you for your support! 🙏
💼 Professional Services
Need help with your PrestaShop store? I offer professional services:
- 🎨 Module Customization - Tailored modifications to fit your specific needs
- 🛒 Complete PrestaShop E-commerce Development - From setup to launch
- ⚡ Performance Optimization - Speed up your store and improve conversions
- 🔧 Custom Module Development - Build exactly what your business needs
- 🆘 Support & Maintenance - Keep your store running smoothly
Contact Me:
---
Made with ❤️ by Ettore Stani
If this module helped you, please consider leaving a ⭐ on GitHub!
Komentarze (0)
Chwilowo nie możesz polubić tej opinii
Zgłoś komentarz
Zgłoszenie wysłane
Twoje zgłoszenie nie może zostać wysłane