0

我在 woocommerce 预订中添加了一些自定义结帐字段。但我注意到自定义字段数据没有与其他常规计费字段一起显示。我怎样才能访问这些数据并打印出来?

    add_action('woocommerce_after_order_notes', 'my_custom_checkout_fields', 20, 1 );
function my_custom_checkout_fields( $checkout ){
     $index = 0;

    echo '<div id="my_custom_checkout_fields"><h2>' .__('Child Information').'</h2>';

                                            // First Loop go through cart items

    foreach(WC()->cart->get_cart() as $cart_item ) 
    {
                                            // 2nd Loop go through each unit related to item quantity
        for( $i = 1; $i <= $cart_item['booking']['_persons']['26819']; $i++ ) 
        {
                    $index++;

                 woocommerce_form_field('my_field_name_'.$index, array(
                    'type' =>'text',
                    'class'=>array('my-field-class form-row-wide'),
                    'label'=>__('Fill this field') . ' ' . $index,
                    'placeholder'=>__('Enter Something'),
             ), $checkout->get_value('my_field_name_'.$index));

        }
    }

    echo '</div>';

}
4

0 回答 0