1 回答

TA貢獻1828條經(jīng)驗 獲得超3個贊
// Add checkout custom text fields
add_action( 'woocommerce_before_order_notes', 'add_checkout_custom_text_fields', 20, 1 );
function add_checkout_custom_text_fields( $checkout) {
$index = 0;
// 1st Loop through cart items
foreach(WC()->cart->get_cart() as $cart_item){
$index++;
// 2nd Loop through each unit related to item quantity
for($i = 1; $i <= $cart_item['booking']['Adults']; $i++){
woocommerce_form_field("Adult[$index][$i]", array(
'type' =>'text',
'class'=>array('my-field-class form-row-wide'),
'label'=>__('Adult Name')." ($i)",
'placeholder'=>__('Enter adult name'),
), $checkout->get_value("Adult[$index][$i]"));
}
for($i = 1; $i <= $cart_item['booking']['Childs']; $i++){
woocommerce_form_field("Child[$index][$i]", array(
'type' =>'text',
'class'=>array('my-field-class form-row-wide'),
'label'=>__('Child Name')." ($i)",
'placeholder'=>__('Enter child name'),
), $checkout->get_value("Child[$index][$i]"));
}
}
}
- 1 回答
- 0 關注
- 93 瀏覽
添加回答
舉報