I've run into a really odd issue I cannot seem to solve. It has to do with a custom field I'm attempting to add to a WooCommerce checkout page.
First, I've created a function to generate an array:
function eci_get_events() {
$args = array(
'post_type' => 'tribe_events',
'posts_per_page' => -1,
'post_status' => 'publish',
'order' => 'ASC',
'orderby' => 'meta_value_num',
'meta_key' => '_EventStartDate'
);
$event_query = new WP_Query($args);
$event_list = array();
if ($event_query->have_posts()) : while ($event_query->have_posts()) : $event_query->the_post();
$event_list[get_the_id()] = get_the_title();
endwhile; endif; wp_reset_postdata();
return $event_list;
}
Which is then used in this function:
function ecitpm_checkout_fields( $fields ) {
$fields['billing']['eci_event'] = array(
'type' => 'select',
'label' => __('Event', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true,
'options' => eci_get_events() // Here's that function
);
return $fields;
}
add_filter( 'woocommerce_checkout_fields', 'ecitpm_checkout_fields' );
No matter what I try, however, this thing does not render on the front end when I utilize the $event_query
loop in the first function. For example:
Works:
$event_list = array();
$event_list[get_the_id()] = get_the_title();
Does not work:
$event_list = array();
if ($event_query->have_posts()) : while ($event_query->have_posts()) : $event_query->the_post();
$event_list[get_the_id()] = get_the_title();
endwhile; endif; wp_reset_postdata();
Edit
As requested, here's a quick var_dump
of the array produced by the eci_get_events()
function:
array(2) {
[11]=>
string(11) "Hello There"
[23]=>
string(12) "Another Test"
}
I've tried just about everything, but haven't been able to find a solution.
Any ideas of how to solve this one?
Thanks! Thomas