Skip to content

Instantly share code, notes, and snippets.

View sidharrell's full-sized avatar

Sidney Harrell sidharrell

  • Vivian-Harrell Web Development Studios, LLC
  • Harpers Ferry, WV, United States
View GitHub Profile
@sidharrell
sidharrell / gist:8106350
Created December 23, 2013 23:06
fix for timeslot reg limit time selector dropdown count
// replaces lines 183-192 of includes/functions/time_date.php:
$SQL .= "( SELECT COALESCE( (SELECT sum(quantity) FROM " . EVENTS_ATTENDEE_TABLE . " ATT ";
$SQL .= "WHERE ATT.event_id= %d ";
$SQL .= "AND ATT.payment_status != 'Incomplete' ";
$SQL .= "AND ATT.event_time = ESE.start_time ";
$SQL .= "AND ATT.end_time = ESE.end_time), 0 ) ) ";
$SQL .= ") AS available_spaces ";
$SQL .= "FROM " . EVENTS_START_END_TABLE . " ESE ";
$SQL .= "WHERE ESE.event_id= %d ";
$SQL .= "GROUP BY ESE.id ";
@sidharrell
sidharrell / gist:7992131
Created December 16, 2013 18:45
custom espresso_update_attendee_payment_status_in_db to work with partial payments
function espresso_update_attendee_payment_status_in_db_custom($payment_data) {
// echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
remove_filter('filter_hook_espresso_update_attendee_payment_data_in_db', 'espresso_update_attendee_payment_status_in_db');
global $wpdb;
$payment_data['payment_date'] = date(get_option('date_format'));
if ($payment_data['payment_status'] == "Completed") {
$payment = $payment_data['total_cost'];
} elseif($payment_data['payment_status'] == "Pending" && !empty($payment_data['amount_paid'])) {
@sidharrell
sidharrell / gist:7947711
Created December 13, 2013 17:15
show cart widget if empty
//replaces lines 24-43 of plugins/espresso-multiple/cart-widget.php
public function widget($args, $instance) {
//if (empty($_SESSION['espresso_session']['events_in_session'])){return;}
extract($args);
global $org_options;
$grand_total = !empty($_SESSION['espresso_session']['grand_total']) ? $_SESSION['espresso_session']['grand_total'] : 0.00;
$title = apply_filters('widget_title', $instance['title']);
echo $before_widget;
echo $before_title . $title . $after_title;
//Debug
@sidharrell
sidharrell / gist:7946710
Last active December 31, 2015 06:19
count number of events in a category
function espresso_count_the_events_in_a_category ($atts) {
extract(shortcode_atts(array('event_category_id' => FALSE), $atts));
if (!$event_category_id) return FALSE;
global $wpdb;
return $wpdb->get_var($wpdb->prepare("SELECT COUNT(ed.id) FROM " . EVENTS_DETAIL_TABLE . " ed JOIN " . EVENTS_CATEGORY_REL_TABLE . " cr ON ed.id = cr.event_id JOIN " . EVENTS_CATEGORY_TABLE . " cd ON cr.cat_id = cd.id WHERE cd.category_identifier = '%s' AND ed.event_status != 'D'", $event_category_id));
}
add_shortcode('COUNT_EVENTS_IN_CATEGORY', 'espresso_count_the_events_in_a_category');
@sidharrell
sidharrell / gist:7895923
Last active December 30, 2015 22:39
fix eway response message
// replaces gateways/eway/ewaypaymentprocess.php lines 87-97
if ($eway_settings['use_sandbox']) {
echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('Debugging / Sandbox output', 'event_espresso') . '</h3><br />';
echo "Response code = " . $responsecode;
echo "\nResponse = ";
var_dump($response);
echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('End of Debugging / Sandbox output (this will go away when you switch to live transactions)', 'event_espresso') . '</h3>';
$subject = 'Instant Payment Notification - Gateway Variable Dump';
$body = "An instant payment notification failed\n";
$body .= "from " . " on " . date('m/d/Y');
@sidharrell
sidharrell / gist:7549987
Last active December 28, 2015 19:29
get a single price sans surcharge
function espresso_return_single_price_sans_surcharge($event_id, $number=0) {
do_action('action_hook_espresso_log', __FILE__, __FUNCTION__, '');
global $wpdb, $org_options;
$number = $number == 0 ? '0,1' : $number . ',' . $number;
$results = $wpdb->get_results("SELECT event_cost FROM " . EVENTS_PRICES_TABLE . " WHERE event_id='" . $event_id . "' ORDER BY id ASC LIMIT " . $number);
if ($wpdb->num_rows > 0) {
foreach ($results as $result) {
$event_cost = $result->event_cost;
@sidharrell
sidharrell / gist:7493110
Last active December 28, 2015 11:28
default to a ticket id
function espresso_ticket_dd($current_value = 0){
if ($current_value == 0)
$current_value = 2; // Change this to the id of the ticket that you would like to be the default ticket.
global $espresso_premium; if ($espresso_premium != true) return;
global $wpdb;
$sql = "SELECT id, ticket_name FROM " .EVENTS_TICKET_TEMPLATES;
$sql .= " WHERE ticket_name != '' ORDER BY ticket_name ";
//echo $sql;
$tickets = $wpdb->get_results($sql);
$num_rows = $wpdb->num_rows;
add_action('action_hook_espresso_save_attendee_data','espresso_create_wp_user', 10, 1);
function espresso_create_wp_user($attendee_data) {
if( username_exists( $attendee_data['email'] ) == NULL ) {
global $org_options;
// Generate the password and create the user
$password = wp_generate_password( 12, false );
$user_id = wp_create_user( $attendee_data['email'], $password, $attendee_data['email'] );
// Set the users details
@sidharrell
sidharrell / gist:7310851
Created November 4, 2013 23:06
fix prepare event_link for events with alternate reg page
function espresso_prepare_event_link_fixed ($payment_data) {
global $wpdb;
remove_filter('filter_hook_espresso_prepare_event_link', 'espresso_prepare_event_link');
$sql = "SELECT ea.event_id, ed.event_name, ed.externalURL FROM " . EVENTS_ATTENDEE_TABLE . " ea";
$sql .= " JOIN " . EVENTS_DETAIL_TABLE . " ed ON ed.id=ea.event_id";
$sql .= " WHERE ea.attendee_session='" . $payment_data['attendee_session'] . "'";
$events = $wpdb->get_results($sql, OBJECT_K);
$payment_data['event_link'] = '';
foreach ($events as $event) {
if (empty($event->externalURL)) {
@sidharrell
sidharrell / gist:7163075
Last active December 26, 2015 14:09
apply coupon code to primary attendee only
function apply_coupon_to_primary_attendee_only ($ext_att_data_source) {
global $wpdb;
$attendee = $wpdb->get_row('SELECT * FROM ' . EVENTS_ATTENDEE_TABLE . ' WHERE id=' . $ext_att_data_source['attendee_id'], ARRAY_A);
if ($attendee['is_primary'] != 1) {
$wpdb->update(EVENTS_ATTENDEE_TABLE,
array('final_price'=>$attendee['orig_price']),
array('id'=>$attendee['id']),
array('%f'),
array('%d'));
}