I have 3 ticket products in WooCommerce and want to add a name field per ticket product purchased - so if a customer buys three tickets 3 name fields are displayed to fill out in the checkout.
The code below works:
// Custom WooCommerce Checkout Fields based on Quantity
add_action( 'woocommerce_before_order_notes', 'person_details' );
function person_details($checkout) {
global $woocommerce;
$count = WC()->cart->get_cart_contents_count();
$i = 1;
for($k=2; $k<= $count; $k++) {
$i++;
print ('<h3>Please enter details of attendee '.$i.'</h3>');
woocommerce_form_field( 'cstm_full_name'.$i, array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Full name'),
'placeholder' => __('Enter full name'),
),
$checkout->get_value( 'cstm_full_name'.$i ));
echo '<div class="clear"></div>';
}
}
But this includes all products added to cart - how can I target specific Product IDs to be only be part of the cart count?
$count = WC()->cart->get_cart_contents_count();