Skip to content

Instantly share code, notes, and snippets.

@sidharrell
Created November 6, 2014 19:42
Show Gist options
  • Select an option

  • Save sidharrell/c248f6905d3d139967c3 to your computer and use it in GitHub Desktop.

Select an option

Save sidharrell/c248f6905d3d139967c3 to your computer and use it in GitHub Desktop.
Volume Discount for EE3 with No Info Required on Additional Attendees
add_action('action_hook_espresso_save_attendee_data', 'apply_volume_discount_hook_function');
function apply_volume_discount_hook_function ( $attendee_data ) {
if ( !empty($attendee_data['event_meta']['VD_threshold']) &&
!empty($attendee_data['event_meta']['VD_discount']) &&
(int)$attendee_data['quantity'] >= (int)$attendee_data['event_meta']['VD_threshold'] ) {
global $wpdb;
$data = array(
'final_price' => max(array( 0, (float)$attendee_data['final_price'] - (float)$attendee_data['event_meta']['VD_discount'] ))
);
$where = array(
'id' => absint( $attendee_data['attendee_id'] )
);
$format = array(
'%f'
);
$where_format = array(
'%d'
);
$wpdb->update( EVENTS_ATTENDEE_TABLE, $data, $where, $format, $where_format );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment