Last active
January 12, 2017 16:42
-
-
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
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
---- 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