Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Created October 23, 2017 13:19
Show Gist options
  • Save Pebblo/d66550019e101a65b021a6fff5ed5c21 to your computer and use it in GitHub Desktop.
Save Pebblo/d66550019e101a65b021a6fff5ed5c21 to your computer and use it in GitHub Desktop.
Remove the promotion code filed if none of the events within the cart have a promotion available.
<?php //Please do not include the opening PHP tag if you already have one
function tw_remove_promo_input( $before_payment_options) {
//If the promotions add-on is not active we don't need any of this to run.
if( class_exists('EEM_Promotion') ) {
$checkout = EE_Registry::instance()->SSN->checkout();
if ( $checkout instanceof EE_Checkout ) {
$transaction = $checkout->transaction;
if ( $transaction instanceof EE_Transaction ) {
//Create an array to hold the event ID's.
$EVT_IDs = array();
//Pull the event ID's from the registrations.
foreach ( $transaction->registrations() as $registration ) {
if ( $registration instanceof EE_Registration ) {
$event = $registration->event();
if ( $event instanceof EE_Event ) {
$EVT_IDs[] = $event->ID();
}
}
}
//We only need each event ID once.
$EVT_IDs = array_unique($EVT_IDs);
//Pull any promotions linked to the events in the cart.
$promotions = EEM_Promotion::instance()->count(
array(
array(
'Promotion_Object.POB_type' => 'Event',
'Promotion_Object.OBJ_ID' => array( 'IN', $EVT_IDs )
)
)
);
//No promtions? Remove the function to add the prmo submit.
if( $promotions == 0 ) {
remove_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', array('EED_Promotions', 'add_promotions_form_inputs') );
}
}
}
}
return $before_payment_options;
}
add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', 'tw_remove_promo_input', 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment