Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barryhughes/c271d3d38ba506deda16d6aa98016034 to your computer and use it in GitHub Desktop.
Save barryhughes/c271d3d38ba506deda16d6aa98016034 to your computer and use it in GitHub Desktop.
<?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