Why Restrict Payment Methods in WooCommerce?
There are several reasons why WooCommerce store owners may want to limit available payment methods:
- Product Restrictions – Some payment gateways do not allow the sale of specific items, such as digital goods, alcohol, or subscription-based products.
- Shipping Constraints – Certain payment options might not be viable based on the shipping method chosen.
- Order Value Limitations – Some stores may only allow certain payment methods for orders above or below a specific amount.
- Customer Location – Payment gateways may not support specific countries or regions.
- Business Policies – Some businesses may prefer bank transfers or cash on delivery for certain products.
By implementing restrictions, store owners can streamline the checkout process and reduce payment failures or order cancellations.
Methods to Restrict Payment Methods in WooCommerce
1. Using WooCommerce’s Built-in Settings
WooCommerce provides some default options to control payment methods:
- Navigate to WooCommerce > Settings > Payments.
- Enable or disable payment gateways based on preference.
- Some gateways, like PayPal and Stripe, allow restrictions based on currency and country.
However, these settings are limited and do not allow restrictions based on cart contents or specific conditions.
2. Using Custom Code to Restrict Payment Methods
For advanced users, adding custom code to the functions.php file allows more flexibility in restricting payment methods. Here’s an example code snippet:
add_filter('woocommerce_available_payment_gateways', 'custom_restrict_payment_methods');
function custom_restrict_payment_methods($available_gateways) {
if (is_admin()) return $available_gateways;
foreach (WC()->cart->get_cart() as $cart_item) {
if ($cart_item['data']->get_id() == 123) { // Replace 123 with your product ID
unset($available_gateways['cod']); // Restrict Cash on Delivery
}
}
return $available_gateways;
}
This code hides the Cash on Delivery (COD) option if a specific product is in the cart.
3. Using a Plugin to Restrict Payment Methods
For store owners who prefer a no-code solution, plugins provide an easy way to implement payment restrictions. Some popular plugins include:
- Conditional Shipping and Payments for WooCommerce
- Hide Payment Method for WooCommerce
- Conditional Payment Methods for WooCommerce
These plugins allow you to set rules based on product categories, cart total, user roles, and more, making it easier to manage payment restrictions.
4. Restricting Payment Methods by Product Category
add_filter('woocommerce_available_payment_gateways', 'restrict_payment_by_category');
function restrict_payment_by_category($available_gateways) {
if (is_admin()) return $available_gateways;
foreach (WC()->cart->get_cart() as $cart_item) {
$terms = get_the_terms($cart_item['product_id'], 'product_cat');
if ($terms) {
foreach ($terms as $term) {
if ($term->slug == 'restricted-category') { // Change to your category slug
unset($available_gateways['paypal']); // Restrict PayPal
}
}
}
}
return $available_gateways;
}
This code hides PayPal if any product in the cart belongs to the restricted-category.
5. Restricting Payment Methods by Cart Total
add_filter('woocommerce_available_payment_gateways', 'restrict_payment_by_cart_total');
function restrict_payment_by_cart_total($available_gateways) {
if (is_admin()) return $available_gateways;
$cart_total = WC()->cart->total;
if ($cart_total > 1000) { // Set your cart total threshold
unset($available_gateways['cod']); // Restrict Cash on Delivery for orders above $1000
}
return $available_gateways;
}
This ensures Cash on Delivery is only available for orders below $1000.
Best Practices for Restricting Payment Methods
To ensure a seamless checkout experience, follow these best practices:
- Test Restrictions Regularly – Always test changes before applying them to a live store to avoid unexpected issues.
- Notify Customers Clearly – If a payment method is unavailable due to cart contents, display a message explaining why.
- Use Plugins for Flexibility – If coding isn’t your strength, use a plugin to manage restrictions without modifying theme files.
- Keep Your Store Updated – Ensure WooCommerce and plugins are up to date to prevent conflicts or security vulnerabilities.
Restricting payment methods in WooCommerce based on cart contents helps store owners optimize their checkout experience, reduce failed transactions, and comply with business policies. Whether using built-in settings, custom code, or a plugin, there’s a solution for every WooCommerce store.
For a hassle-free way to restrict payment methods, try using the Conditional Payment Methods for WooCommerce plugin. It offers extensive control over payment restrictions, ensuring a smooth and tailored checkout process.