wooccm_radio_handler

The WooCommerce Checkout Manager wooccm radio handler function.

Description

wooccm_radio_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_radio_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_radio_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_radio_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. $field = '<div class="form-row ' . esc_attr( implode( ' ', $args['class'] ) ) .'" id="' . esc_attr( $key ) . '_field">'; 
  26.  
  27. $field .= '<fieldset><legend>' . $args['label'] . $required . '</legend>'; 
  28.  
  29. if ( ! empty( $args['options'] ) ) 
  30.  
  31. foreach ( explode('||', $args['options']) as $option_key => $option_text ) 
  32. $field .= '<label><input type="radio" ' . checked( $value, wpml_string_wccm_pro( esc_attr( $option_text ) ), false ) . ' name="' . esc_attr( $key ) . '" value="' . wpml_string_wccm_pro( esc_attr( $option_text ) ). '" /> ' . wpml_string_wccm_pro( esc_html( $option_text ) ). '</label>'; 
  33.  
  34. $field .= '</fieldset></div>' . $after; 
  35.  
  36. return $field; 
  37.