Oguzhan Altun
April 5, 2016 at 3:28 pm
Hello,
I suddenly started to see the following error message in the EE4 table view:
Warning: array_shift() expects parameter 1 to be array, string given in /home/clients/1d989383ee11099bb2d8468c003d5c0c/web/wp-content/uploads/espresso/templates/template.oa.php on line 132
You can see the error here: https://www.genevaphotoclub.com/dates-prices/
Could you help?
Here is the code on template.oa.php:
Line 132:
$ticket = array_shift( $tickets );
Full code:
<?php
// Options
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
// Load Venue View Helper
EE_Registry::instance()->load_helper('Venue_View');
//Defaults
$reg_button_text = !isset($reg_button_text) ? __('Register', 'event_espresso') : $reg_button_text;
$alt_button_text = !isset($alt_button_text) ? __('View Details', 'event_espresso') : $alt_button_text;//For alternate registration pages
$sold_out_button_text = !isset($sold_out_button_text) ? __('Sold Out', 'event_espresso') : $sold_out_button_text;//For sold out events
if ( have_posts() ) :
// allow other stuff
do_action( 'AHEE__espresso_events_table_template_template__before_loop' );
?>
<?php if ($category_filter != 'false'){ ?>
<p class="category-filter">
<label><?php echo __('Category Filter', 'event_espresso'); ?></label>
<select class="" id="ee_filter_cat">
<option class="ee_filter_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
<?php
$taxonomy = array('espresso_event_categories');
$args = array('orderby'=>'name','hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);
foreach($ee_terms as $term){
echo '<option class="' . $term->slug . '">'. $term->name . '</option>';
}
?>
</select>
</p>
<?php } ?>
<?php if ($footable != 'false' && $table_search != 'false'){ ?>
<p>
<?php echo __('Search:', 'event_espresso'); ?> <input id="filter" type="text"/>
</p>
<?php } ?>
<table id="ee_filter_table" class="espresso-table footable table" data-page-size="<?php echo $table_pages; ?>" data-filter="#filter">
<thead class="espresso-table-header-row">
<tr>
<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
<th class="th-group"><?php _e('Day','event_espresso'); ?></th>
<th style="text-align:center" class="th-group"><?php _e('Time','event_espresso'); ?></th>
<th class="th-group"><?php _e('Course','event_espresso'); ?></th>
<th style="text-align:center" class="th-group"><?php _e('Lang.','event_espresso'); ?></th>
<th style="text-align:center" class="th-group"><?php _e('Price','event_espresso'); ?></th>
<th class="th-group" data-sort-ignore="true"></th>
</tr>
</thead>
<?php if ($footable != 'false' && $table_paging != 'false'){ ?>
<tfoot>
<tr>
<td colspan="5">
<div class="pagination pagination-centered"></div>
</td>
</tr>
</tfoot>
<?php } ?>
<tbody>
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the post TYPE-specific template for the content.
global $post;
//Debug
//d( $post );
//Get the category for this event
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ) {
if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
// loop thru terms and create links
$category_slugs = '';
foreach ( $event_categories as $term ) {
$category_slugs[] = $term->slug;
}
$category_slugs = implode(' ', $category_slugs);
} else {
// event has no terms
$category_slugs = '';
}
}
//Create the event link
$external_url = $post->EE_Event->external_url();
$button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
$registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();
//OA Add: Language
$languages = get_the_tags();
//Create the register now button
$live_button = '<a class="register-button" id="a_register_link-'.$post->ID.'" href="'.$registration_url.'">'.$button_text.'</a>';
if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
$live_button = '<a id="a_register_link-'.$post->ID.'" class="soldout-button" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
}
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
$datetime = end( $datetimes );
if ( ! ($event->is_sold_out() || $event->is_sold_out( TRUE ) ) ) {
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = reset( $tickets );
//check if the ticket is free, if set the ticket price to 'Free'
if ( $ticket instanceof EE_Ticket ) {
$ticket_price = $ticket->pretty_price();
$ticket_price_data_value = $ticket->price();
$ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
}
//Get the remaining ticket values for the next datetime.
$tickets_remaining = $datetime->tickets_remaining() === EE_INF ? __('Unlimited','event_espresso') : $datetime->tickets_remaining();
} else {
//The event is sold out, set the ticket price to 'N/A'
$ticket_price = __( 'N/A', 'event_espresso');
}
$startdate = date_i18n( $date_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) );
$starttime = date_i18n( 'G:i', strtotime( $datetime->start_time('H:i:s') ) );
$endtime = date_i18n( 'G:i', strtotime( $datetime->end_time('H:i:s') ) );
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = array_shift( $tickets );
$ticket_price = $ticket instanceof EE_Ticket ? $ticket->ticket_price() . '<span class="currency-code"> (CHF)</span>' : '';
$ticket_price_data_value = $ticket instanceof EE_Ticket ? $ticket->price() : '';
$tickets_price_free_check = $ticket_price_data_value == 0 ? __('Free','event_espresso') : $ticket_price;
// OA Add so that it doesn't show free for full events
$tickets_price_free_check = (string)$ticket_price_data_value == '' ? __('Sold Out','event_espresso') : $tickets_price_free_check;
// grab primary datetime for event
$first_datetime = espresso_event_date_obj( $post->ID );
$tickets_left = $first_datetime instanceof EE_Datetime ? $first_datetime->tickets_remaining() : 0;
$tickets_left = $tickets_left === INF ? __('unlimited','event_espresso') : $tickets_left;
?>
<tr class="espresso-table-row <?php echo $category_slugs; ?>">
<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo $datetime->get_raw( 'DTT_EVT_start' ); ?>"><?php echo $startdate; ?></td>
<td class="day_of_week event-<?php echo $post->ID; ?>"><?php espresso_event_date_range( 'l', ' ', 'l', ' ', $event->ID() ); ?></td>
<td style="text-align:center" class="time event-<?php echo $post->ID; ?>"><?php echo $starttime ; ?> - <?php echo $endtime ; ?></td>
<td class="event_title event-<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></td>
<td style="text-align:center" class="languages-<?php echo $post->ID; ?>">
<?php
if( $languages ) {
foreach ($languages as $lang) {
echo $lang->name . ' ';
}
}
?>
</td>
<td style="text-align:center" class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $ticket_price; ?></td>
<td style="text-align:center" class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
</tr>
<?php
endwhile;
echo '</table>';
// allow moar other stuff
do_action( 'AHEE__espresso_events_table_template_template__after_loop' );
else :
// If no content, include the "No posts found" template.
espresso_get_template_part( 'content', 'none' );
endif;
Tony
April 5, 2016 at 4:03 pm
Add New Note to this Reply
Its caused by your 2 events that are sold out.
I provided updates to the code Lorenzo used and he updated his tutorial here:
https://gist.github.com/lorenzocaum/ef6afefd07c9c5f6f681
It looks like you have added my code, but then a few lines below it continue to use the old code.
This code:
$datetime = end( $datetimes );
if ( ! ($event->is_sold_out() || $event->is_sold_out( TRUE ) ) ) {
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = reset( $tickets );
//check if the ticket is free, if set the ticket price to 'Free'
if ( $ticket instanceof EE_Ticket ) {
$ticket_price = $ticket->pretty_price();
$ticket_price_data_value = $ticket->price();
$ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
}
//Get the remaining ticket values for the next datetime.
$tickets_remaining = $datetime->tickets_remaining() === EE_INF ? __('Unlimited','event_espresso') : $datetime->tickets_remaining();
} else {
//The event is sold out, set the ticket price to 'N/A'
$ticket_price = __( 'N/A', 'event_espresso');
}
Is designed to replace this code:
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = array_shift( $tickets );
$ticket_price = $ticket instanceof EE_Ticket ? $ticket->ticket_price() . '<span class="currency-code"> (CHF)</span>' : '';
$ticket_price_data_value = $ticket instanceof EE_Ticket ? $ticket->price() : '';
$tickets_price_free_check = $ticket_price_data_value == 0 ? __('Free','event_espresso') : $ticket_price;
// OA Add so that it doesn't show free for full events
$tickets_price_free_check = (string)$ticket_price_data_value == '' ? __('Sold Out','event_espresso') : $tickets_price_free_check;
// grab primary datetime for event
$first_datetime = espresso_event_date_obj( $post->ID );
$tickets_left = $first_datetime instanceof EE_Datetime ? $first_datetime->tickets_remaining() : 0;
$tickets_left = $tickets_left === INF ? __('unlimited','event_espresso') : $tickets_left;
But you are using both in your template.
Basically when an event is sold out, espresso_event_tickets_available() returns and empty string, meaning $tickets == ”.
array_shift() is then being used on an empty string, and throws that error, so your template needs to be updated to use the amended code I provided above which checks if the event is sold out and skips the ticket checks you are using.
Oguzhan Altun
April 5, 2016 at 4:13 pm
Add New Note to this Reply
hi, so I removed the second part from the template. now the error message disappeared, but the chf currency sign shows twice. How to fix that one? I like the superscript CHF so I’d ideally like the remove the CHF sign right next to the number.
https://www.genevaphotoclub.com/dates-prices/
Oguzhan Altun
April 6, 2016 at 2:13 am
Add New Note to this Reply
Previously we solved the same issue with this, but I cannot find any “$tickets_price_free_check” any more in the new code.
https://eventespresso.com/topic/add-price-as-separate-column-in-the-events-table-view/
Tony
April 6, 2016 at 6:37 am
Add New Note to this Reply
Your ogirinal code used ticket_price() and build your own ‘pretty’ version of the price:
$ticket_price = $ticket instanceof EE_Ticket ? $ticket->ticket_price() . '<span class="currency-code"> (CHF)</span>' : '';
The new version uses the built in pretty_price() method:
$ticket_price = $ticket->pretty_price();
It is not due to the $ticket_price_data_value
check, that was for free events.
You’ll need to modify the function to use ticket_price() in place of the above and build out your own string for the price if that what you prefer.
But it sounds like you are still using both versions of the code and that’s why an additional currency is being added to the price.
Oguzhan Altun
April 6, 2016 at 6:49 am
Add New Note to this Reply
Hi Tony,
I removed the second part of the code, so it should be only the necessary code right now. Could you advice how i can fix this double currency code issue?
<?php
// Options
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
// Load Venue View Helper
EE_Registry::instance()->load_helper('Venue_View');
//Defaults
$reg_button_text = !isset($reg_button_text) ? __('Register', 'event_espresso') : $reg_button_text;
$alt_button_text = !isset($alt_button_text) ? __('View Details', 'event_espresso') : $alt_button_text;//For alternate registration pages
$sold_out_button_text = !isset($sold_out_button_text) ? __('Sold Out', 'event_espresso') : $sold_out_button_text;//For sold out events
if ( have_posts() ) :
// allow other stuff
do_action( 'AHEE__espresso_events_table_template_template__before_loop' );
?>
<?php if ($category_filter != 'false'){ ?>
<p class="category-filter">
<label><?php echo __('Category Filter', 'event_espresso'); ?></label>
<select class="" id="ee_filter_cat">
<option class="ee_filter_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
<?php
$taxonomy = array('espresso_event_categories');
$args = array('orderby'=>'name','hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);
foreach($ee_terms as $term){
echo '<option class="' . $term->slug . '">'. $term->name . '</option>';
}
?>
</select>
</p>
<?php } ?>
<?php if ($footable != 'false' && $table_search != 'false'){ ?>
<p>
<?php echo __('Search:', 'event_espresso'); ?> <input id="filter" type="text"/>
</p>
<?php } ?>
<table id="ee_filter_table" class="espresso-table footable table" data-page-size="<?php echo $table_pages; ?>" data-filter="#filter">
<thead class="espresso-table-header-row">
<tr>
<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
<th class="th-group"><?php _e('Day','event_espresso'); ?></th>
<th style="text-align:center" class="th-group"><?php _e('Time','event_espresso'); ?></th>
<th class="th-group"><?php _e('Course','event_espresso'); ?></th>
<th style="text-align:center" class="th-group"><?php _e('Lang.','event_espresso'); ?></th>
<th style="text-align:center" class="th-group"><?php _e('Price','event_espresso'); ?></th>
<th class="th-group" data-sort-ignore="true"></th>
</tr>
</thead>
<?php if ($footable != 'false' && $table_paging != 'false'){ ?>
<tfoot>
<tr>
<td colspan="5">
<div class="pagination pagination-centered"></div>
</td>
</tr>
</tfoot>
<?php } ?>
<tbody>
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the post TYPE-specific template for the content.
global $post;
//Debug
//d( $post );
//Get the category for this event
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ) {
if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
// loop thru terms and create links
$category_slugs = '';
foreach ( $event_categories as $term ) {
$category_slugs[] = $term->slug;
}
$category_slugs = implode(' ', $category_slugs);
} else {
// event has no terms
$category_slugs = '';
}
}
//Create the event link
$external_url = $post->EE_Event->external_url();
$button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
$registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();
//OA Add: Language
$languages = get_the_tags();
//Create the register now button
$live_button = '<a class="register-button" id="a_register_link-'.$post->ID.'" href="'.$registration_url.'">'.$button_text.'</a>';
if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
$live_button = '<a id="a_register_link-'.$post->ID.'" class="soldout-button" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
}
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
$datetime = end( $datetimes );
if ( ! ($event->is_sold_out() || $event->is_sold_out( TRUE ) ) ) {
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = reset( $tickets );
//check if the ticket is free, if set the ticket price to 'Free'
if ( $ticket instanceof EE_Ticket ) {
$ticket_price = $ticket->pretty_price();
$ticket_price_data_value = $ticket->price();
$ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
}
//Get the remaining ticket values for the next datetime.
$tickets_remaining = $datetime->tickets_remaining() === EE_INF ? __('Unlimited','event_espresso') : $datetime->tickets_remaining();
} else {
//The event is sold out, set the ticket price to 'N/A'
$ticket_price = __( 'N/A', 'event_espresso');
}
$startdate = date_i18n( $date_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) );
$starttime = date_i18n( 'G:i', strtotime( $datetime->start_time('H:i:s') ) );
$endtime = date_i18n( 'G:i', strtotime( $datetime->end_time('H:i:s') ) );
?>
<tr class="espresso-table-row <?php echo $category_slugs; ?>">
<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo $datetime->get_raw( 'DTT_EVT_start' ); ?>"><?php echo $startdate; ?></td>
<td class="day_of_week event-<?php echo $post->ID; ?>"><?php espresso_event_date_range( 'l', ' ', 'l', ' ', $event->ID() ); ?></td>
<td style="text-align:center" class="time event-<?php echo $post->ID; ?>"><?php echo $starttime ; ?> - <?php echo $endtime ; ?></td>
<td class="event_title event-<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></td>
<td style="text-align:center" class="languages-<?php echo $post->ID; ?>">
<?php
if( $languages ) {
foreach ($languages as $lang) {
echo $lang->name . ' ';
}
}
?>
</td>
<td style="text-align:center" class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $ticket_price; ?></td>
<td style="text-align:center" class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
</tr>
<?php
endwhile;
echo '</table>';
// allow moar other stuff
do_action( 'AHEE__espresso_events_table_template_template__after_loop' );
else :
// If no content, include the "No posts found" template.
espresso_get_template_part( 'content', 'none' );
endif;
Tony
April 6, 2016 at 7:05 am
Add New Note to this Reply
When posting cost please use a service such as pastebin.com create a gist and post the link here, its much easier to read.
This is not caused by the template, I used the code you posted above and loaded the events table, I only see a single currency – http://take.ms/juQpv
Have you altered Event Espresso or hired a developer to customize the output?
Tony
April 6, 2016 at 7:07 am
Add New Note to this Reply
Note the same happens on the ticket selector – http://take.ms/S387i
Can you take a screenshot of the ticket editor within one of your events and post the link for us to view it here please.
https://eventespresso.com/wiki/troubleshooting-checklist/#screenshots
Oguzhan Altun
April 6, 2016 at 7:44 am
Add New Note to this Reply
Hi,
Sorry for the long code, I didn’t know about these services, I will use them from now on.
I didn’t alter EE or didn’t hire any developer to do so.
With ticket editor, you mean this screen?
http://grab.by/PhQs
Josh
April 6, 2016 at 9:31 am
Add New Note to this Reply
Hi Oguzhan,
You can remove the CHF sign right next to the number by going to Event Espresso > General Settings > Countries Tab. Then you select your country, then you remove CHF from the Currency Sign input. There you can input a + sign, something else, or leave it blank. Then you save the settings.
Oguzhan Altun
April 6, 2016 at 9:46 am
Add New Note to this Reply
hi Josh,
I just tried that, and now I have a strange ¤ symbol instead of the CHF… ?
Josh
April 6, 2016 at 9:52 am
Add New Note to this Reply
Can you put
in the input field?
Oguzhan Altun
April 6, 2016 at 9:58 am
Add New Note to this Reply
that replaced ¤ with a space (here ). any way to remove the space too?
Josh
April 6, 2016 at 10:04 am
Add New Note to this Reply
No not really.
Oguzhan Altun
April 6, 2016 at 10:10 am
Add New Note to this Reply
in that case can I remove the (chf) from the table and from the event ticket selector? Ideally I need CHF right next to the price without a space 🙂
It’s not urgent though, I could wait until the next release if it’s easier to put it into the plugin directly.
Josh
April 6, 2016 at 10:36 am
Add New Note to this Reply
No it can’t be removed.
Josh
April 6, 2016 at 10:40 am
Add New Note to this Reply
That said, you can set Currency Sign Before Number to Yes and that will make it display the CHF right next to the price without a space.
Josh
July 14, 2016 at 12:15 pm
Add New Note to this Reply
The ¤ symbol has been removed from Event Espresso 4.9.3.p. So you can go to your Country settings, remove the space from the currency symbol field, and it will no longer display anything there.
Oguzhan Altun
July 14, 2016 at 1:29 pm
Add New Note to this Reply
perfect, looks much better now. thank you!