wooccm_multicheckbox_handler

The WooCommerce Checkout Manager wooccm multicheckbox handler function.

Description

wooccm_multicheckbox_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_multicheckbox_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_multicheckbox_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_multicheckbox_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.  
  16. if ( ( ! empty( $args['clear'] ) ) ) $after = '<div class="clear"></div>'; else $after = ''; 
  17.  
  18. if ( $args['wooccm_required'] ) { 
  19. $args['class'][] = 'validate-required'; 
  20. $required = ' <abbr class="required" title="' . esc_attr__( 'required', 'woocommerce' ) . '">*</abbr>'; 
  21. } else { 
  22. $required = ''; 
  23.  
  24. $args['maxlength'] = ( $args['maxlength'] ) ? 'maxlength="' . absint( $args['maxlength'] ) . '"' : ''; 
  25.  
  26. $options = ''; 
  27.  
  28. if ( ! empty( $args['options'] ) ) 
  29. foreach (explode('||', $args['options']) as $option_key => $option_text ) 
  30. $options .= '' . wpml_string_wccm_pro( esc_attr( $option_text ) ) .' <input type="checkbox" name="' . esc_attr( $key ) . '[]" value="'.wpml_string_wccm_pro( esc_attr( $option_text ) ).'" '. selected( $value, $option_key, false ) . ' /><br />'; 
  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 .= '' . $options . ' 
  38. </p>' . $after; 
  39.  
  40. return $field;