troubleshooting Question

Need to echo string on the select options instead of value.

Avatar of Alicia St Rose
Alicia St RoseFlag for United States of America asked on
4 Comments1 Solution34 ViewsLast Modified:
I need to echo the string of a select dropdown. I keep getting the value echoed. For instance I'd like my string Santa Barbara, yada yada" echoed instead of santabarbara. I don't know what I need to change get_value() to, if that's even what I'm to change.  Thanks for any help, ya'll!

Here's my code:

//* 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>'.__('Choose your Pickup Location').'</h2>';

	woocommerce_form_field( 'location', array(
	    'type'          => 'select',
	    'class'         => array( 'wps-drop' ),
	    'label'         => __( 'Delivery options' ),
	    'options'       => array(
	    	'blank'		=> __( 'Select Pickup Location', 'wps' ),
	        'santabarbara'	=> __( 'Santa Barbara, 33 W Parker Way', 'wps' ),
	        'montecito'	=> __( 'Montecito, 1187 Coast Village Road', 'wps' ),
	        'carpinteria' 	=> __( 'Carpinteria, 4185 Carpinteria Ave', 'wps' )

	$checkout->get_value( 'location' ));


//* Process the checkout
 add_action('woocommerce_checkout_process', 'wps_select_checkout_field_process');
 function wps_select_checkout_field_process() {
    global $woocommerce;

    // Check if set, if its not set add an error.
    if ($_POST['location'] == "blank")
     wc_add_notice( '<strong>Please select a Pickup Location under Delivery options</strong>', 'error' );


//* Update the order meta with field value
 add_action('woocommerce_checkout_update_order_meta', 'wps_select_checkout_field_update_order_meta');
 function wps_select_checkout_field_update_order_meta( $order_id ) {

   if ($_POST['location']) update_post_meta( $order_id, 'location', esc_attr($_POST['location']));


//* Display field value on the order edition page
add_action( 'woocommerce_admin_order_data_after_billing_address', 'wps_select_checkout_field_display_admin_order_meta', 10, 1 );
function wps_select_checkout_field_display_admin_order_meta($order){

	echo '<p><strong>'.__('Pickup Location').':</strong> ' . get_post_meta( $order->id, 'location', true ) . '</p>';


//* Add selection field value to emails
add_filter('woocommerce_email_order_meta_keys', 'wps_select_order_meta_keys');
function wps_select_order_meta_keys( $keys ) {

	$keys['Pickup Location:'] = 'location';
	return $keys;

Open in new window

Alicia St Rose
WordPress Dev & WordPress Coach

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004