在wordpress数据库中,我有一个名为tab_clients的表 在此表中,我具有以下列: id,名称,cpf,cnpj,即razao_social,电子邮件,电话,手机,代表(wordpress用户ID),状态,照片,date_since,data_cadastro
我需要将这些值带入woocommerce的结帐形式的选择字段中,但是当我声明变量'options'=> array($ client-> name)时,它只会给我带来一个结果。
add_action( 'woocommerce_after_order_notes', 'cliente_woocommerce' );
function cliente_woocommerce( $checkout ) {
echo '<div id="cliente_woocommerce"><h2>' . __('Cliente') . '</h2>';
$clientes = $wpdb->get_results( "SELECT id, nome, cnpj FROM tab_clientes" );
foreach($clientes as $cliente);
woocommerce_form_field( 'cliente', array(
'type' => 'select',
'class' => array('cliente form-row-wide'),
'label' => __('Campo de Teste (Cliente)'),
'placeholder' => __('Selecione o cliente'),
'options' => array($cliente->nome),
), $checkout->get_value( 'cliente' ) );
echo '</div>';
答案 0 :(得分:0)
尝试以下重新访问的代码,该代码将为您为该签出自定义选择字段提供具有多个值的正确选项数组:
add_action( 'woocommerce_after_order_notes', 'cliente_woocommerce' );
function cliente_woocommerce( $checkout )
{
global $wpdb;
$results = $wpdb->get_results( "SELECT id, nome, cnpj FROM tab_clientes" );
$otions = array( '' => __('Selecione o cliente') );
// Loop through the data query results
foreach($results as $result) {
$options[$result->id] = $result->nome;
}
echo '<div id="cliente_woocommerce"><h2>' . __('Cliente') . '</h2>';
woocommerce_form_field( 'cliente', array(
'type' => 'select',
'class' => array('cliente form-row-wide'),
'label' => __('Campo de Teste (Cliente)'),
'options' => $options,
), $checkout->get_value( 'cliente' ) );
echo '</div>';
}