所以我有以下代码:
/**
Add custom fields to user / checkout - Date + Venue
*/
add_action( \'woocommerce_after_order_notes\', \'my_custom_checkout_field\' );
function my_custom_checkout_field( $checkout ) {
if( have_rows(\'date_venue\', 424) ): $x = 1;
while ( have_rows(\'date_venue\', 424) ) : the_row(); ?>
<?php $dates[] = get_sub_field(\'date\').\' - \'.get_sub_field(\'session_time\'); ?>
<?php $x++; endwhile;
else : endif;
echo \'<div id="bv_custom_checkout_field"><h4>Select Course Date/Venue</h4>\';
woocommerce_form_field( \'course_venue\', array(
\'type\' => \'select\',
\'class\' => array(\'my-class form-row-wide\'),
\'label\' => __(\'Select Course Date / Venue\'),
\'placeholder\' => __(\'Course Date/Venue\'),
\'options\' => array(
$dates[0] => __( $dates[0], \'wps\' ),
$dates[1] => __( $dates[1], \'wps\' ),
$dates[2] => __( $dates[2], \'wps\' )
),
),
get_user_meta( get_current_user_id(),\'course_venue\' , true ) ); echo \'</div>\';
}
如您所见,我添加了$dates[]作为一个数组,其范围可以是2-X选项,这将取决于产品ID。
例如,我手动包含了这些选项,即。dates[0]
, dates[1]
等
我将如何循环此内容并将其包含在options
大堆
它工作正常,但不是动态的。
非常感谢您的帮助!