woocommerce_wp_select

Output a select input box.

Description

woocommerce_wp_select( (array) $field ); 

Parameters (1)

0. $field (array)
The field.

Usage

  1. if ( !function_exists( 'woocommerce_wp_select' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/admin/wc-meta-box-functions.php'; 
  3.  
  4. // The field. 
  5. $field = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = woocommerce_wp_select($field); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/wc-meta-box-functions.php  
  1. function woocommerce_wp_select( $field ) { 
  2. global $thepostid, $post; 
  3.  
  4. $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; 
  5. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'select short'; 
  6. $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; 
  7. $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; 
  8. $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true ); 
  9. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  10. $field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; 
  11.  
  12. // Custom attribute handling 
  13. $custom_attributes = array(); 
  14.  
  15. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { 
  16.  
  17. foreach ( $field['custom_attributes'] as $attribute => $value ) { 
  18. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  19.  
  20. echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"> 
  21. <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>'; 
  22.  
  23. if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { 
  24. echo wc_help_tip( $field['description'] ); 
  25.  
  26. echo '<select id="' . esc_attr( $field['id'] ) . '" name="' . esc_attr( $field['name'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" ' . implode( ' ', $custom_attributes ) . '>'; 
  27.  
  28. foreach ( $field['options'] as $key => $value ) { 
  29. echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>'; 
  30.  
  31. echo '</select> '; 
  32.  
  33. if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { 
  34. echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; 
  35.  
  36. echo '</p>';