Created
April 22, 2015 00:46
-
-
Save kharissulistiyo/e8825a9d66a768fd1a71 to your computer and use it in GitHub Desktop.
Woocommerce Custom Product Data Fields: Update checkbox field to allow it to be checked by default. https://wordpress.org/plugins/woocommerce-custom-product-data-fields/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Update the checkbox field whith this one | |
*/ | |
case 'checkbox': | |
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; | |
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'checkbox'; | |
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; | |
$field['value'] = isset( $options_data[0][$field_id] ) ? $options_data[0][$field_id] : ''; | |
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'yes'; | |
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; | |
$field['checked'] = isset( $field['checked'] ) ? $field['checked'] : ''; | |
$default_is_checked = ( $field['checked'] == true ) ? 'checked="checked"' : ''; | |
echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label><input '.$default_is_checked.' type="checkbox" class="' . esc_attr( $field['class'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . ' /> '; | |
if ( ! empty( $field['description'] ) ) { | |
if ( isset( $field['desc_tip'] ) && false !== $field['desc_tip'] ) { | |
echo '<img class="help_tip" data-tip="' . esc_attr( $field['description'] ) . '" src="' . esc_url( WC()->plugin_url() ) . '/assets/images/help.png" height="16" width="16" />'; | |
} else { | |
echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; | |
} | |
} | |
echo '</p>'; | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment