我在我的网站上使用Woocommerce,在结帐页面上,我有一个带有单选按钮的自定义选择结帐字段。我正在函数中使用此工作片段。php:
/**
* Add the field to the checkout
**/
add_action( \'woocommerce_after_order_notes\', \'custom_select_field\' );
function hear_about_us_field( $checkout ) {
echo \'<div id="custom-field"><h3>\'
. __( \'2. Pick an option\' )
. \'</h3>\';
woocommerce_form_field_radio(
\'custom_field\',
array(
\'type\' => \'select\',
\'class\' => array(
\'custom-select-field\'
),
\'label\' => __( \'\' ),
\'placeholder\' => __( \'\' ),
\'required\' => true,
\'options\' => array(
\'Option 1\' => \'Option 1\',
\'Option 2\' => \'Option 2\',
\'Option 3\' => \'Option 3\'
)
),
$checkout->get_value( \'custom_field\' )
);
echo \'</div>\';
}
如您所见,我手动添加了3个选择选项。我想要的是根据自定义帖子类型动态添加选项。显示自定义帖子类型时,我通常会运行如下循环:
<?php $loop = new WP_Query( array( \'post_type\' => \'organisationer\') ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php the_title(); ?>
<?php endwhile; wp_reset_query(); ?>
如何在checkout函数中实现此循环?s例如,我想要CPT的标题,而不是“选项1”,“选项2”。