WooCommerce Bookings participant information at checkout

Viewed 20

With this project customers are able to book a course for themselves or for multiple people. The information of the person that is booking is collected at checkout but I would like to collect information for all the other participants as well. I have been experimenting with the code below. Although the looks need some attention it is working for the 'cart count'.

    add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
    
    function my_custom_checkout_field( $checkout ) {
    global $woocommerce;
    
    $class_basket_count = $woocommerce->cart->cart_contents_count;
    $class_basket_count = $class_basket_count - 1;
    if($class_basket_count >= 1){
        echo '<div id="my_custom_checkout_field"><h3>' . __('Participant List') . '</h3>';
        for ($i=1; $i <= $class_basket_count; $i++ ){
    
            woocommerce_form_field( 'guest-name-'.$i, array(
                'type'          => 'text',
                'class'         => array('my-field-class form-row-wide'),
                'label'         => __('Guest Name'),
                'placeholder'   => __('Enter Name'),
                ), $checkout->get_value( 'guest-name-'.$i ));
    
            woocommerce_form_field( 'guest-email-'.$i, array(
                'type'          => 'text',
                'class'         => array('my-field-class form-row-wide'),
                'label'         => __('Guest Email'),
                'placeholder'   => __('Enter Email'),
                ), $checkout->get_value( 'guest-email-'.$i ));
        }
        echo '</div>';
    }
    }

As WooCommerce Bookings works with 'Persons' I would like to change the code above to work of the amount of persons in the booking. From my understanding the only thing that would need to be changed to achieve that is '$woocommerce->cart->cart_contents_count;' in '$class_basket_count = $woocommerce->cart->cart_contents_count;'

I could be completely mistaken and that it turns out to be a lot more complex then this but hopefully someone could enlighten me.

0 Answers
Related