Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Forked from digitalchild/product-edit.php
Created January 6, 2016 02:07
Show Gist options
  • Save bentasm1/5c50137c9faf448a9e5d to your computer and use it in GitHub Desktop.
Save bentasm1/5c50137c9faf448a9e5d to your computer and use it in GitHub Desktop.
WC Vendors Pro Form Input Type Examples
<?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