Conditionally hiding available gateways in WooCommerce
-
WC Version 2.5.5
I have a specific product that cannot be paid for online for legal reasons, though it can be ordered via COD. I have written a method hook to hide the payment form (Inspire Commerce credit card payments) when that product is in the cart. When I echo out $available_gateways I see two options in the array, ‘cod’ and ‘inspire’ – but when I hide Inspire with the method below, they both go away and I get the error message:
Sorry, it seems that there are no available payment methods for your state. Please contact us if you require assistance or wish to make alternate arrangements.
Any thoughts on why I can’t just have COD?
function dfg_hide_payment_form($available_gateways) { if ($_customer['dfg-pay-later-enabled'] == 1) { if( is_checkout() ) { global $woocommerce, $_customer; $packages = $_customer['dfg-package-ids']; foreach ($packages as $package) { if (dfg_woo_in_cart($package)) { unset($available_gateways['inspire']); } } } } else { unset($available_gateways['cod']); } } add_filter('woocommerce_available_payment_gateways', 'dfg_hide_payment_form', 1);
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Conditionally hiding available gateways in WooCommerce’ is closed to new replies.