I am running an online-store selling grills. Only the grills are shipped via a specific carrier where additional informations are needed.
I managed to display a dropdown when a certain product_ID is in the cart. When a specific value is selected a text-area is displayed.
This should happen for about 10 products, not just one.
After reading a number of threads and searching the web, i cant figure out, how to add more than one product_ID.
add_action( 'woocommerce_after_order_notes', 'grills_versandauswahl_checkout_field' );
function grills_versandauswahl_checkout_field( $checkout ) {
$grill_in_cart = grills_is_conditional_product_in_cart ( 125 );
if ( $grill_in_cart === true ) {
echo '<div id="my_custom_checkout_field"><h3>' . __( 'Versandoptionen' ) . '</h3><p style="margin: 0 0 8px;">text</p>';
woocommerce_form_field( 'versandoption', array(
'type' => 'select',
'class' => array( 'wps-drop' ),
'label' => __( 'Versandoptionen' ),
'required' => true,
'options' => array(
'blank' => __( 'Auswählen', 'wps' ),
'fixtermin' => __( 'Fixtermin', 'wps' ),
'avis' => __( 'Telefonisches Avis', 'wps' ),
)
), $checkout->get_value( 'versandoption' ) );
woocommerce_form_field( 'inscription_textbox', array(
'type' => 'textarea',
'class' => array( 'inscription-text form-row-wide' ),
'label' => __( 'Wunschtermin / Ablageort' ),
), $checkout->get_value( 'inscription_textbox' ) );
echo '</div>';
}
}
function grills_is_conditional_product_in_cart( $product_id ) {
//Check to see if user has product in cart
global $woocommerce;
//flag no book in cart
$grill_in_cart = false;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if ( $_product->id === $product_id ) {
//book is in cart!
$grill_in_cart = true;
}
}
return $grill_in_cart;
}