Home › Forums › WC Vendors Pro Support › Adding NEW fields to Product Form
NOTICE: We've Moved to a Ticket System for Support
As of August 31, 2017 (12am EST) our support forums will be retired (read-only), and we will be moving to a support ticket system. This will allow us to better organize and answer support requests, and provide a more personalized experience as we assist our customers.
For the time being, we will leave our forums open for reading and learning while we work on creating a more robust Knowledge Base for everyone to use.
If you are a WC Vendors Pro customer please open a support ticket here. If you are a WC Vendors user please open a support ticket on the Wordpress.org forums.
The information on this forum is outdated and in most instances no longer relevant. Please be sure to check our documentation for the most up to date information.
Thank you to all of our customers!
- This topic has 29 replies, 4 voices, and was last updated 6 years, 9 months ago by trish johnson.
-
AuthorPosts
-
January 4, 2016 at 4:48 am #19806Karen ThomasParticipant
Hi Ben and @DigitalChild
Is there a knowledge base article coming soon for how to add new fields to product-edit.php?
I no longer wish to do this via ACF, ideally I would be able to delete the ACF plug in and use the WCVendors method for adding new fields 🙂
Many thanks,
Karen
January 4, 2016 at 10:30 pm #19925WC Vendors SupportParticipantHi Karen,
I hope you feel super loved. I wrote this just for you.
https://www.wcvendors.com/kb/adding-a-custom-field-for-products/
Ben
January 5, 2016 at 10:31 am #19946Karen ThomasParticipantGosh I’m feeling exceptionally loved!!! <3 🙂
Thank you thank you thank you!Eeeek so excited! It’s displayed 🙂
Can I be cheeky and ask for more help?
1. How do I change from a textarea to a small text box so the Crafties just add the number of days in there? Or better still a number selection box like the Stock Quantity box 😉
2. How do I display on the website Product pages? I’d want to show ‘Handmade in XX days’ filling in the XX with what the Craftie has entered in the box.Thanks for all your help 🙂
Karen
January 5, 2016 at 12:31 pm #19971WC Vendors SupportParticipant1.) Good question! I’m not entirely sure. 🙂 @digitalchild
2.) Sure! I’ve updated the gist with an extra section of code that will display it on single product pages, and update the KnowledgeBase article with it accordingly.
January 5, 2016 at 1:11 pm #19976Karen ThomasParticipantYay thank you so much I’m chuffed to bits! 😀 😀 😀
Look at this!
For previous products, I manually typed ‘Handmade in XX days’ to every product description!
As existing products won’t have this shiny new field filled in, is there a little trick to hide the words ‘No of days to hand make’ from the website product pages when the field is empty?Rather than me need to enter the number of days in the new field for over 1000 products do you know?
Many thanks!
Karen
January 5, 2016 at 1:44 pm #19982WC Vendors SupportParticipantadd_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 if ( isset ( $output ) ) { echo 'Ingredients: ' . $output . '<br>'; } }
The changes we made there, is we check “if $output is set, then echo out the text, otherwise do nothing”. 🙂
Looks good!
January 5, 2016 at 2:45 pm #19987Karen ThomasParticipantThanks Ben,
Did I do this right:
add_action('woocommerce_product_meta_start', 'wcv_handmade', 2); function wcv_handmade() { $output = get_post_meta( get_the_ID(), '_wcv_custom_product_handmade', true ); // Change _wcv_custom_product_handmade to your meta key if ( isset ( $output ) ) { echo 'Days to Hand Make: ' . $output . '<br>'; } }
As it still showed the ‘Days to hand make:’ text on the product pages.
Thanks,
Karen
January 5, 2016 at 4:20 pm #19990WC Vendors SupportParticipantTry this instead:
add_action('woocommerce_product_meta_start', 'wcv_handmade', 2); function wcv_handmade() { $output = get_post_meta( get_the_ID(), '_wcv_custom_product_handmade', true ); // Change _wcv_custom_product_handmade to your meta key if ( !empty ( $output ) ) { echo 'Days to Hand Make: ' . $output . '<br>'; } }
January 5, 2016 at 5:33 pm #20008Karen ThomasParticipantThank you soon very very very much! 😀
With the handmade field filled in:
Altered the code slightly to give me the above 🙂
echo '<Strong><font size="4">HANDMADE IN ' . $output . ' DAYS</font></strong><br>';
And when the handmade field isn’t filled in 🙂
HUGE happy dance!!! 🙂
January 5, 2016 at 5:54 pm #20010Karen ThomasParticipantSo just need Jamie’s @DigitalChild help now to change the text area to either a small text box or preferably a drop down option box like the Stock Qty field
Could it be something like this?:
<?php $options = array("1", "2", "3");
Many thanks,
Karen
January 5, 2016 at 7:06 pm #20023WC Vendors SupportParticipantThat looks great. The strong really makes it PoP!
On the textarea part, I tried to figure it out, I failed. 🙂 Jamie will steer us both in the right direction on this one. He just landed in India for a few weeks there so we’ll see him back most likely tonight. 🙂
January 5, 2016 at 7:21 pm #20025Karen ThomasParticipantAwe thanks for trying I kept failing too! God loves a trier tho 😉
Welcome to India Jamie! 😀
January 5, 2016 at 7:44 pm #20030Karen ThomasParticipantAlso not essential, but if there was a way for us all to pop our new custom fields in wp-admin product pages, it would make it easier to review before publishing. Otherwise we’ll need to switch users to check they have filled in the field and if not fill it in for them. As much as I love the UserSwitching plug in, it might be a bit long winded lol! 😉
January 5, 2016 at 7:46 pm #20032WC Vendors SupportParticipantWooCommerce already shows you any custom meta keys, just enable that meta box by clicking “Screen Options” at the top right of your edit product page. 🙂
January 5, 2016 at 8:14 pm #20033WC Vendors SupportParticipantKB article updated! For a single row for text, not textarea:
January 5, 2016 at 9:02 pm #20038Karen ThomasParticipantHiya Ben,
Woo hoo! Thank you! Perfect!!! 🙂
I can’t find the Handmade metakey in my “Screen Options” is there something I need to do to add it to WooCommerce first do you think?
Many thanks,
Karen
January 5, 2016 at 9:09 pm #20041WC Vendors SupportParticipantCheck the “Custom Fields” box. 🙂
January 5, 2016 at 9:18 pm #20042Karen ThomasParticipantI did try that but got this funny box..
Then I thought I’d try adding a new Custom Field and just had lots of attributes to select from:
Any ideas, I must be doing something wrong sorry!
Thanks v much,
Karen
January 5, 2016 at 9:36 pm #20044WC Vendors SupportParticipantOops. Our oops.
If the meta key is _wcv_blahblahblah the first _ means it’s a hidden key for the custom field.
In v1.2.0 we will make it so that:
_wcv_custom_product is hidden
and
wcv_custom_product is shown
So, keep that code handy but dont use it yet. And take the first _ off the meta key. Once v1.2.0 goes live in a bit here, then you can use the code and all is well.
January 5, 2016 at 9:45 pm #20047Karen ThomasParticipantYay thanks very much! 🙂
Thanks for all your help today!
February 1, 2016 at 1:31 pm #22522Karen ThomasParticipantHiya Ben,
I noticed in the change log for v1.2.0 you guys have made it so:
_wcv_custom_product is hidden
and
wcv_custom_product is shown
Does that mean I change this in my functions.php?
From:
add_action('woocommerce_product_meta_start', 'wcv_handmade', 2); function wcv_handmade() { $output = get_post_meta( get_the_ID(), '_wcv_custom_product_handmade', true ); // Change _wcv_custom_product_handmade to your meta key if ( !empty ( $output ) ) { echo '<Strong><font size="4">HANDMADE IN ' . $output . ' DAYS</font></strong><br>'; } }
To (remove _ before wcv_custom_product_handmade):
add_action('woocommerce_product_meta_start', 'wcv_handmade', 2); function wcv_handmade() { $output = get_post_meta( get_the_ID(), 'wcv_custom_product_handmade', true ); // Change _wcv_custom_product_handmade to your meta key if ( !empty ( $output ) ) { echo '<Strong><font size="4">HANDMADE IN ' . $output . ' DAYS</font></strong><br>'; } }
And my new field for Handmade in xx days will appear in wp-admin product pages?
Ta,
Karen
February 1, 2016 at 1:34 pm #22524WC Vendors SupportParticipantYou’re close.
WooCommerce looks at meta keys with a _ and does not show them on the edit order page, the _ means they are hidden. So, we added the other meta key, and if you use that, then the custom fields will show up in the “Custom Fields” meta box on the edit order page.
If you want the field to be hidden on the edit product page, use the _, otherwise use the non-_ 🙂
February 3, 2016 at 5:55 pm #22874Karen ThomasParticipantHiya Ben,
So do I go into my product-edit.php template and just remove the underscore from here:
and do I then remove the underscore in my functions.php too?
And will doing that have any risk of removing the data entered in the field previously or is it safe? (sorry feel the need for handholding in case I mess up!)
Many thanks,
Karen
February 3, 2016 at 6:01 pm #22875WC Vendors SupportParticipantIf you remove the _ from the code, all the meta keys with the _ in it will still exist on previously edited products. If you’re showing the custom field on your single product page, you’d have to update that code, too.
If you remove the _ you will have two meta keys, the _ on old products, and no _ on new products. Kindof a bitch.
But what you can do easy enough is run through your database and go to the post_meta table — search and replace _wcv_custom_product_handmade with wcv_custom_product_handmade and then all existing products will have the new meta key and all is well. 🙂
February 3, 2016 at 6:38 pm #22890Karen ThomasParticipantEeeek database… I’m scared, very scared! 😉 Can you show me how I access the tables and what they’re called?
Ta very much,
Karen 🙂February 3, 2016 at 8:05 pm #22898WC Vendors SupportParticipantHit me up on Skype and we can do it when you have 10 free minutes. Since you’re a webhosting customer of ours, too, I can point you to the exact places to touch and do everything. Then you’ll be a database wizzzzzzzzzard!
February 6, 2016 at 6:34 am #23181Karen ThomasParticipantOh wow thank you sooooo much Ben! That would be amazing, would love a little lesson when you have time. I’ll send you a message on Skype later to see when you’re free 🙂
May 22, 2016 at 1:04 am #32941MKCParticipantHi Concious Crafties, i was just wondering, what made you go away from using ACF?
May 22, 2016 at 2:12 am #32943Karen ThomasParticipantHi @[email protected],
Good question. I saw that it was possible to add custom fields within WCVendors Pro product form, so as I only used ACF for one field I made the switch. ACF was really stable and good plug in but I’m hoping eventually WCVendros Pro can do all the things my many plug ins do for my site now. I don’t like having lots of plug ins due to conflicts that can happen.
I really love my custom field Ben helped me with! 🙂
Karen
June 29, 2017 at 11:12 pm #69197trish johnsonParticipantThanks for this code, it’s exactly what I was looking for! But instead of not showing the field if its left blank i’d like to show the text “Ready to Post”.
I understand that this part –> if ( !empty ( $output ) )
is the bit that hides the field, but I don’t understand the code enough to know how or what to change it to. Can you please give me some pointers? -
AuthorPosts
- The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.