无法在 woocommerce 中添加自定义 select 字段

Unable to add custom select field in woocommerce

我想向结帐页面添加自定义字段 options。我正在使用以下代码:

$fields['billing']['billing_options'] = array(
    'label'       => __('Options', 'woocommerce'),
    'placeholder' => _x('', 'placeholder', 'woocommerce'),
    'required'    => false,
    'clear'       => false,
    'type'        => 'select',
    'options'     => array(
        'option_a' => __('option a', 'woocommerce' ),
        'option_b' => __('option b', 'woocommerce' )
        )
    );

我想显示数据库中的选项 (option_a,option_b) 或 我想用动态数据,想用options菜单里的for loop

如何在这个函数中使用 for 循环?

之前就这样做,像这样:

add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

function my_custom_checkout_fields( $fields ) {

    $args = array(                                                                  
        'post_type'         => array('options'),                                    
        'posts_per_page'    => -1                                                           
    );                                                                              

    $posts = new WP_Query($args);
    $options = array();        

    foreach ($posts as $post) {  
        $options[$post->ID] => attr_esc($post->post_title);
    }

    $fields['billing']['billing_options'] = array(
        'label'       => __('Options', 'woocommerce'),
        'placeholder' => _x('', 'placeholder', 'woocommerce'),
        'required'    => false,
        'clear'       => false,
        'type'        => 'select',
        'options'     => $options
    );
    return $fields;
}