get_post_meta > Get value of selectbox
-
Hi,
I’m having trouble to get the value of a selectbox displayed in frontend.
I have hooked an extra custom (product) field to the single product page.
I create a custom field in backend:
function extra_product_field() { woocommerce_wp_select( array( 'id' => 'myfieldname', 'label' => __( 'My Select Field', 'woocommerce' ), 'options' => array( 'one' => __( 'Option 1', 'woocommerce' ), 'two' => __( 'Option 2', 'woocommerce' ), 'three' => __( 'Option 3', 'woocommerce' ) ) ) ); } add_action( 'woocommerce_product_options_pricing', 'extra_product_field' );
Save it:
update_post_meta( $post_id, 'myfieldname', esc_attr( $_POST['myfieldname'] ) );
Display value in frontend:
function show_extra_product_field() { echo get_post_meta(get_the_ID(), 'myfieldname', true); } add_action( 'woocommerce_single_product_summary', 'show_extra_product_field' );
Step 3 is causing this, in frontend this is displayed when I choose Option 2 in backend: ‘two’
How can I display the value in stead of the option, it should be: ‘Option 2’
Guido
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘get_post_meta > Get value of selectbox’ is closed to new replies.