I need help integrating Custom Post types into Woocommerce checkout page - I need to populate all the custom fields related to a CPT based on the selection made from the selct field - which populates CPT cars for the user logged in -
woocommerce_form_field( 'car_sel', array(
'type' => 'select',
'class' => 'populate-cars',
'label' => __('Car for this Event'),
'options' => my_acf_load_field( array($carname) ),
), $checkout->get_value( 'car_sel' ));
function my_acf_load_field( $field )
{
get_currentuserinfo();
$id = get_current_user_id();
$args = array(
'author' => $id,
'posts_per_page' => -1,
'orderby' => 'post_title',
'order' => 'ASC',
'post_type' => 'car',
'post_status' => 'publish' );
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$carname[$post->post_title] = $post->post_title;
}
// Important: return the field
return $carname;
}
Now I need to populate fields like make, model & cc into Woocommerce field and pass them onto the email - I also want to change the variables depending on the select - So I need onchange functionality
Can anyone help me? Struggling to get meta values based on post title - nothing seems to be working :(
I have written very extensively about customizing the WooCommerce checkout. Here's the first part (displaying the form field on the checkout adapted to your select options. Depending on if you start getting really long lists of cars, you may want to look into the Transient API to cache the
$posts
values. Also for reference,wp_list_pluck()
is awesome.