wooccm_select_handler

The WooCommerce Checkout Manager wooccm select handler function.

Description

wooccm_select_handler( $field, $key, $args, $value ); 

Parameters (4)

0. $field
The field.
1. $key
The key.
2. $args
The args.
3. $value
The value.

Usage

  1. if ( !function_exists( 'wooccm_select_handler' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-checkout-manager/includes/classes/field_filters.php'; 
  3.  
  4. // The field. 
  5. $field = null; 
  6.  
  7. // The key. 
  8. $key = null; 
  9.  
  10. // The args. 
  11. $args = null; 
  12.  
  13. // The value. 
  14. $value = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = wooccm_select_handler($field, $key, $args, $value); 
  18.  

Defined (1)

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

/includes/classes/field_filters.php  
  1. function wooccm_select_handler( $field = '', $key, $args, $value ) { 
  2. global $current_user; 
  3. $user_roles = $current_user->roles; 
  4. $user_role = array_shift($user_roles); 
  5.  
  6. if( !empty($args['user_role']) && (!empty($args['role_options']) || !empty($args['role_options2'])) ) { 
  7. $rolekeys = explode('||', $args['role_options']); 
  8. $rolekeys2 = explode('||', $args['role_options2']); 
  9. if (!empty($args['role_options']) && !in_array($user_role, $rolekeys)) { 
  10. return; 
  11. if (!empty($args['role_options2']) && in_array($user_role, $rolekeys2)) { 
  12. return; 
  13. }  
  14.  
  15. if ( ( ! empty( $args['clear'] ) ) ) $after = '<div class="clear"></div>'; else $after = ''; 
  16.  
  17. if ( $args['wooccm_required'] ) { 
  18. $args['class'][] = 'validate-required'; 
  19. $required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>'; 
  20. } else { 
  21. $required = ''; 
  22.  
  23. $args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : ''; 
  24.  
  25. $options = ''; 
  26.  
  27. if ( ! empty( $args['options'] ) ) 
  28. $options .= ($args['default']) ?'<option value="">' . $args['default'] .'</option>': ''; 
  29. foreach (explode('||', $args['options']) as $option_key => $option_text ) 
  30. $options .= '<option '. selected( $value, $option_key, false ) . '>' . wpml_string_wccm_pro( esc_attr( $option_text ) ) .'</option>'; 
  31.  
  32. $field = '<p class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">'; 
  33.  
  34. if ( $args['label'] ) 
  35. $field .= '<label for="' . esc_attr( $key ) . '" class="' . implode( ' ', $args['label_class'] ) .'">' . $args['label']. $required . '</label>'; 
  36.  
  37. $field .= '<select class="' . esc_attr( $args['fancy'] ) .'" data-placeholder="' . __( ''.$args['default'].'', 'wc_checkout_fields' ) . '" name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '" > 
  38. ' . $options . ' 
  39. </select> 
  40. </p>' . $after; 
  41.  
  42. return $field; 
  43.