Created
September 1, 2015 15:30
-
-
Save Welland/ecd3080fa1cebe691565 to your computer and use it in GitHub Desktop.
WooCommerce API - Input Functions
This file contains hidden or 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
/** | |
* Text Input | |
*/ | |
woocommerce_wp_text_input( | |
array( | |
'id' => '_text_field', | |
'label' => __( 'My Text Field', 'woocommerce' ), | |
'placeholder' => 'http://', | |
'desc_tip' => 'true', | |
'description' => __( 'Enter the custom value here.', 'woocommerce' ) | |
) | |
); | |
/** | |
* Number Field | |
*/ | |
woocommerce_wp_text_input( | |
array( | |
'id' => '_number_field', | |
'label' => __( 'My Number Field', 'woocommerce' ), | |
'placeholder' => '', | |
'description' => __( 'Enter the custom value here.', 'woocommerce' ), | |
'type' => 'number', | |
'custom_attributes' => array( | |
'step' => 'any', | |
'min' => '0' | |
) | |
) | |
); | |
/** | |
* Textarea | |
*/ | |
woocommerce_wp_textarea_input( | |
array( | |
'id' => '_textarea', | |
'label' => __( 'My Textarea', 'woocommerce' ), | |
'placeholder' => '', | |
'description' => __( 'Enter the custom value here.', 'woocommerce' ) | |
) | |
); | |
/** | |
* Select | |
*/ | |
woocommerce_wp_select( | |
array( | |
'id' => '_select', | |
'label' => __( 'My Select Field', 'woocommerce' ), | |
'options' => array( | |
'one' => __( 'Option 1', 'woocommerce' ), | |
'two' => __( 'Option 2', 'woocommerce' ), | |
'three' => __( 'Option 3', 'woocommerce' ) | |
) | |
) | |
); | |
/** | |
* Checkbox | |
*/ | |
woocommerce_wp_checkbox( | |
array( | |
'id' => '_checkbox', | |
'wrapper_class' => 'show_if_simple', | |
'label' => __('My Checkbox Field', 'woocommerce' ), | |
'description' => __( 'Check me!', 'woocommerce' ) | |
) | |
); | |
/** | |
* Hidden Field | |
*/ | |
woocommerce_wp_hidden_input( | |
array( | |
'id' => '_hidden_field', | |
'value' => 'hidden_value' | |
) | |
); | |
/** | |
* Product Select | |
*/ | |
?> | |
<p class="form-field product_field_type"> | |
<label for="product_field_type"><?php _e( 'Product Select', 'woocommerce' ); ?></label> | |
<select id="product_field_type" name="product_field_type[]" class="ajax_chosen_select_products" multiple="multiple" data-placeholder="<?php _e( 'Search for a product…', 'woocommerce' ); ?>"> | |
<?php | |
$product_field_type_ids = get_post_meta( $post->ID, '_product_field_type_ids', true ); | |
$product_ids = ! empty( $product_field_type_ids ) ? array_map( 'absint', $product_field_type_ids ) : null; | |
if ( $product_ids ) { | |
foreach ( $product_ids as $product_id ) { | |
$product = get_product( $product_id ); | |
$product_name = woocommerce_get_formatted_product_name( $product ); | |
echo '<option value="' . esc_attr( $product_id ) . '" selected="selected">' . esc_html( $product_name ) . '</option>'; | |
} | |
} | |
?> | |
</select> <img class="help_tip" data-tip='<?php _e( 'Your description here', 'woocommerce' ) ?>' src="<?php echo $woocommerce->plugin_url(); ?>/assets/images/help.png" height="16" width="16" /> | |
</p> | |
<?php |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment