Created
January 6, 2016 01:44
-
-
Save digitalchild/ff25d9d2a01b22ce3a49 to your computer and use it in GitHub Desktop.
WC Vendors Pro Form Input Type Examples
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
<?php | |
/** | |
* Example text input with validation | |
*/ | |
WCVendors_Pro_Form_Helper::input( | |
array( | |
'post_id' => $object_id, | |
'id' => '_wcv_custom_product_example_text_input', | |
'label' => __( 'Product Meta Text Input', 'wcvendors-pro' ), | |
'placeholder' => __( 'Product Meta Text Input', 'wcvendors-pro' ), | |
'desc_tip' => 'true', | |
'description' => __( 'This displays under the field. ', 'wcvendors-pro' ), | |
'custom_attributes' => array( | |
'data-rules' => 'required', | |
'data-error' => __( 'This is a required field.', 'wcvendors-pro' ) | |
) | |
) | |
); | |
// Get the meta field | |
// Call this in your template or via an action such as product meta | |
function wcv_example_text_input_meta() { | |
$output = get_post_meta( get_the_ID(), '_wcv_custom_product_example_text_input', true ); | |
echo 'My example text input: ' . $output . '<br>'; | |
} | |
add_action('woocommerce_product_meta_start', 'wcv_example_text_input_meta', 2 ); | |
/** | |
* Example checkbox no validation | |
*/ | |
WCVendors_Pro_Form_Helper::input( | |
array( | |
'post_id' => $object_id, | |
'id' => '_wcv_custom_product_example_checkbox', | |
'label' => __( 'Product Meta Checkbox', 'wcvendors-pro' ), | |
'type' => 'checkbox' | |
) | |
); | |
// Get the meta field | |
// Call this in your template or via an action such as product meta | |
function wcv_example_checkbox_meta() { | |
$output = get_post_meta( get_the_ID(), '_wcv_custom_product_example_checkbox', true ); | |
if ( isset( $output ) && 'yes' === $output ){ | |
echo 'This was checked.'; | |
} else { | |
echo 'This was not checked.'; | |
} | |
} | |
add_action('woocommerce_product_meta_start', 'wcv_example_checkbox_meta', 2 ); | |
/** | |
* Example text area | |
*/ | |
WCVendors_Pro_Form_Helper::textarea( array( | |
'post_id' => $object_id, | |
'id' => '_wcv_custom_product_example_text_area', | |
'label' => __( 'Product Meta Text area', 'wcvendors-pro' ), | |
'placeholder' => __( 'Product Meta Text area', 'wcvendors-pro' ), | |
'desc_tip' => 'true', | |
'description' => __( 'This displays under the field. ', 'wcvendors-pro' ), | |
) ); | |
// Get the meta field | |
// Call this in your template or via an action such as product meta | |
function wcv_example_textarea_meta() { | |
$output = get_post_meta( get_the_ID(), '_wcv_custom_product_example_text_area', true ); | |
echo 'My example text input: ' . $output . '<br>'; | |
} | |
add_action('wcv_example_textarea_meta', 'wcv_example_checkbox_meta', 2 ); | |
/** | |
* Exmaple Select | |
*/ | |
WCVendors_Pro_Form_Helper::select( | |
array( | |
'post_id' => $object_id, | |
'id' => '_wcv_custom_product_example_select', | |
'label' => __( 'Product Meta Select', 'wcvendors-pro' ), | |
'wrapper_start' => '<div class="all-100">', | |
'wrapper_end' => '</div>', | |
'options' => array( | |
'' => __('', 'wcvendors-pro'), | |
'1' => __( 'Option One', 'wcvendors-pro' ), | |
'2' => __( 'Option Two', 'wcvendors-pro' ), | |
'3' => _x( 'Option Three', 'wcvendors-pro' ) | |
) | |
) | |
); | |
// Get the meta field | |
// Call this in your template or via an action such as product meta | |
function wcv_example_select_meta() { | |
$output = get_post_meta( get_the_ID(), '_wcv_custom_product_example_select', true ); | |
echo 'My example select: ' . $output . '<br>'; | |
} | |
add_action('wcv_example_textarea_meta', 'wcv_example_select_meta', 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment