I have some code to add a select field in Woocommerce Checkout page that is working fine with basic options in the array (Prisoner 1 & Prisoner 2). There are only two options, and I need to populate each of those with two pieces of concatenated user metadata :
Option 1: echo get_user_meta( $user_id, ‘prisoner_1’, true ) . ’ - ’ . get_user_meta( $user_id, ‘prisoner_1_number’, true );
Option 2: echo get_user_meta( $user_id, ‘prisoner_2’, true ) . ’ - ’ . get_user_meta( $user_id, ‘prisoner_2_number’, true );
The code that I am using is as follows:
//* Add select field to the checkout page
add_action(‘woocommerce_before_order_notes’, ‘wps_add_select_checkout_field’);
function wps_add_select_checkout_field( $checkout ) {
echo '<h2>'.__('Prisoner Details').'</h2>';
woocommerce_form_field( 'prisoner', array(
'type' => 'select',
'class' => array( 'wps-drop' ),
'label' => __( 'Select Prisoner' ),
'options' => array(
'blank' => __( 'Select Prisoner', 'wps' ),
'Prisoner 1' => __( 'Prisoner 1', 'wps' ),
'Prisoner 2' => __( 'Prisoner 2', 'wps' ),
)
),
$checkout->get_value( 'prisoner' ));
}
Please can someone help me with the correct syntax to accomplish this. I cannot find anything online.
Many thanks!