[ad_1]
[ad_2]
I run a woocommerce site.
Need to turn-on payment option for certain products (not all because they require shipping to be quoted)
Any recommendations as how to set this up?
I've looked in settings and for plugins… google is getting worse with AI suggestions
Many thanks again to this community!
Paid – [https://woocommerce.com/products/conditional-shipping-and-payments/](https://woocommerce.com/products/conditional-shipping-and-payments/)
Free – With custom code or CSS to hide the payment divs.
Conditional Payment Gateways for WooCommerce
If you prefer not to use plugins or need more control, you can use a custom code.
You can add this code to your Theme’s functions.php:
add_filter(‘woocommerce_available_payment_gateways’, ‘custom_payment_gateway_restriction’);
function custom_payment_gateway_restriction($available_gateways) {
if (!is_admin()) {
// Loop through each product in the cart
foreach (WC()->cart->get_cart() as $cart_item_key => $cart_item) {
$product = $cart_item[‘data’];
// Check if the product requires a shipping quote
if (has_term(‘shipping-quote-required’, ‘product_cat’, $product->get_id())) {
// Remove specific payment gateways for these products
unset($available_gateways[‘paypal’]); // Example: Remove PayPal
}
}
}
return $available_gateways;
}
// Replace `’`shipping-quote-required`’` with the actual slug of your category.
// Modify the `unset` line to match the payment gateways you want to disable (e.g., `’paypal’`).