Skip to content

Instantly share code, notes, and snippets.

@bentasm1
Last active January 12, 2017 16:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bentasm1/9c1ea6cc4984ef283c72 to your computer and use it in GitHub Desktop.
Save bentasm1/9c1ea6cc4984ef283c72 to your computer and use it in GitHub Desktop.
WC Vendors Pro - Adding a custom field to your add/edit product page
---- The code below goes in your product-edit.php template as outline in the KnowledgeBase Article ----
<?php
WCVendors_Pro_Form_Helper::textarea( array(
'post_id' => $object_id,
'id' => 'wcv_custom_product_ingredients',
'label' => __( 'Ingredients', 'wcvendors-pro' ),
'placeholder' => __( 'Ingredients', 'wcvendors-pro' ),
'desc_tip' => 'true',
'description' => __( 'The product ingredients', 'wcvendors-pro' ),
) );
?>
Alternatively, instead of a text area, you can have a single line for text:
<?php
WCVendors_Pro_Form_Helper::input( array(
'type' => 'text',
'post_id' => $object_id,
'id' => 'wcv_custom_product_ingredients',
'label' => __( 'Ingredients', 'wcvendors-pro' ),
'placeholder' => __( 'Ingredients', 'wcvendors-pro' ),
'desc_tip' => 'true',
'description' => __( 'The product ingredients', 'wcvendors-pro' ),
) );
?>
---- This code will display the vales on the single product page. Add this code to your themes functions.php file ----
add_action('woocommerce_product_meta_start', 'wcv_ingredients', 2);
function wcv_ingredients() {
$output = get_post_meta( get_the_ID(), 'wcv_custom_product_ingredients', true ); // Change wcv_custom_product_ingredients to your meta key
echo 'Ingredients: ' . $output . '<br>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment