woocommerce_wp_checkbox

Output a checkbox input box.

Description

woocommerce_wp_checkbox( (array) $field ); 

Parameters (1)

0. $field (array)
The field.

Usage

  1. if ( !function_exists( 'woocommerce_wp_checkbox' ) ) { 
  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_checkbox($field); 
  9.  

Defined (1)

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

/includes/admin/wc-meta-box-functions.php  
  1. function woocommerce_wp_checkbox( $field ) { 
  2. global $thepostid, $post; 
  3.  
  4. $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; 
  5. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox'; 
  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['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes'; 
  10. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  11. $field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; 
  12.  
  13. // Custom attribute handling 
  14. $custom_attributes = array(); 
  15.  
  16. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { 
  17.  
  18. foreach ( $field['custom_attributes'] as $attribute => $value ) { 
  19. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  20.  
  21. echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"> 
  22. <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>'; 
  23.  
  24. if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { 
  25. echo wc_help_tip( $field['description'] ); 
  26.  
  27. echo '<input type="checkbox" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' ' . implode( ' ', $custom_attributes ) . '/> '; 
  28.  
  29. if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { 
  30. echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; 
  31.  
  32. echo '</p>';