I have entered this code into my functions.php but only the second product field (302) is showing in test orders in the admin section. Is there a way to get the 2nd product (294)to pass to the admin with this implementation?
add_action( 'woocommerce_checkout_fields', 'woo_add_conditional_checkout_fields' );
function woo_add_conditional_checkout_fields( $fields ) {
foreach( WC()->cart->get_cart() as $cart_item ){
$product_id = $cart_item['product_id'];
if( $product_id == 294 ) {
$fields['billing']['billing_field_' . $product_id] = array(
'label' => __( 'Enter License Plate and State' ),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
}
if( $product_id == 302 ) {
$fields['billing']['billing_field_' . $product_id] = array(
'label' => __( 'Enter License Plate, State AND CITATION Number' ),
'required' => true,
'class' => array('form-row-wide'),
'clear' => true
);
}
}
// Return checkout fields.
return $fields;
}
