Woocommerce, payment gateways for downloads
-
I would like to restrict the payment gateways for downloadable products. Now a customer can order a downloadable product and pay by COD. Even if the payment isn’t made, the customer can go to his account en download the product.
The option to let customers download direct after the checkout have to stay.
In short,
– Payment Gateways should be limited for downloadable products (only iDeal by Mollie and no COD, Cheque, Bacs).
– Direct download after the checkout page have to remain.I found this code somewhere which restrict ‘categories’, i’m trying to shape it to my needs. But since i’m not an expert, i definitely need some help 🙂
function filter_gateways($gateways){ $payment_NAME = 'paypal'; // <--------------- change this $category_ID = '20'; // <----------- and this global $woocommerce; foreach ($woocommerce->cart->cart_contents as $key => $values ) { // Get the terms, i.e. category list using the ID of the product $terms = get_the_terms( $values['product_id'], 'product_cat' ); // Because a product can have multiple categories, we need to iterate through the list of the products category for a match foreach ($terms as $term) { // 20 is the ID of the category for which we want to remove the payment gateway if($term->term_id == $category_ID){ unset($gateways[$payment_NAME]); // If you want to remove another payment gateway, add it here i.e. unset($gateways['cod']); break; } break; } } return $gateways; } add_filter('woocommerce_available_payment_gateways','filter_gateways');
If somebody could help it would be great!
Thanks anyway!
- The topic ‘Woocommerce, payment gateways for downloads’ is closed to new replies.