Created
April 26, 2018 05:22
-
-
Save barryhughes/c271d3d38ba506deda16d6aa98016034 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Unset the cheque payment option if any of the existing cart items happen to | |
* be a ticket for an event which belongs to a specific category. | |
* | |
* @param array $available_gateways | |
* | |
* @return array | |
*/ | |
function maybe_unset_gateway_by_category( $available_gateways ) { | |
$watch_list = array( 123, 456, 789 ); | |
$etp_wc = Tribe__Tickets_Plus__Commerce__WooCommerce__Main::get_instance(); | |
foreach ( wc()->cart->cart_contents as $key => $values ) { | |
$event = $etp_wc->get_event_for_ticket( $values['product_id'] ); | |
if ( ! $event ) { | |
continue; | |
} | |
$event_categories = tribe_get_event_cat_ids( $event->ID ); | |
foreach ( $event_categories as $category_id ) { | |
if ( in_array( $category_id, $watch_list ) ) { | |
unset( $available_gateways['cheque'] ); | |
break 2; | |
} | |
} | |
} | |
return $available_gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'maybe_unset_gateway_by_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment