【发布时间】:2019-09-01 11:51:20
【问题描述】:
我正在尝试在 WooCommerce 中将 options 参数数组设置为 woocommerce_form_field()。
这是我将数组动态添加到 $GLOBALS 的代码:
foreach($kekei as $goods=> $goodness) {
$balbal."'".[$goodness['shipping_code']] = $goodness['shipping_name'];
}
$GLOBALS['hariharis'] = $balbal;
所以我在woocommerce_form_field() 的options 参数中使用它:
add_action( 'woocommerce_review_order_after_shipping', 'custom_shipping_radio_button', 20);
$domain = 'woocommerce';
if ( WC()->session->get( 'chosen_shipping_methods' )[0] == targeted_shipping_method() ) :
echo '<tr class="delivery-radio"><th>' . __('Delivery options', $domain) . '</th><td>';
$chosen = WC()->session->get('chosen_delivery');
$chosen = empty($chosen) ? WC()->checkout->get_value('delivery') : $chosen;
$chosen = empty($chosen) ? 'regular' : $chosen;
// Add a custom checkbox field
woocommerce_form_field( 'radio_delivery', array(
'type' => 'radio',
'class' => array( 'form-row-wide' ),
/*
'options' => array(
'regular' => __('Regular', $domain),
'premium' => __('Premium +'.wc_price(2.00), $domain),
'big' => __('Big +'.wc_price(3.00), $domain),
'small' => __('Big +'.wc_price(5.00), $domain),
*/
'options' => $GLOBALS['hariharis'],
'default' => $chosen,
), $chosen );
echo '</td></tr>';
endif;
}
所以这里我使用变量$GLOBALS['hariharis'] 在woocommerce_form_field() 中动态传递options 参数,但是我收到了这个错误:
“警告:array_keys() 期望参数 1 为数组,在 " 中给出 null。
我做错了什么?任何帮助表示赞赏。
【问题讨论】:
标签: php arrays wordpress woocommerce field