Created
August 15, 2013 04:49
-
-
Save DevinVinson/6238339 to your computer and use it in GitHub Desktop.
Function based on this topic http://wordpress.org/support/topic/restrict-payment-options-based-on-product Small changes and fix to get the function to loop through all categories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Filter gateways on specific category ID | |
* | |
**/ | |
function filter_gateways($gateways){ | |
$category_ID = '17'; | |
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) { | |
if($term->term_id == $category_ID){ | |
unset($gateways['paypal']); | |
unset($gateways['cheque']); | |
break; | |
} | |
} | |
} | |
return $gateways; | |
} | |
add_filter('woocommerce_available_payment_gateways','filter_gateways'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment