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.

https://docs.wcvendors.com/

Thank you to all of our customers!

 

Viewing 30 posts - 1 through 30 (of 30 total)
  • Author
    Posts
  • #19806
    Karen Thomas
    Participant

    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

    #19925
    WC Vendors Support
    Participant

    Hi 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

    #19946
    Karen Thomas
    Participant

    Gosh 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

    #19971
    WC Vendors Support
    Participant

    1.) 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.

    https://gist.github.com/bentasm1/9c1ea6cc4984ef283c72

    #19976
    Karen Thomas
    Participant

    Yay 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

    #19982
    WC Vendors Support
    Participant
    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
        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!

    #19987
    Karen Thomas
    Participant

    Thanks 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

    #19990
    WC Vendors Support
    Participant

    Try 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>';
        }
    }
    #20008
    Karen Thomas
    Participant

    Thank 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!!! 🙂

    #20010
    Karen Thomas
    Participant

    So 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

    #20023
    WC Vendors Support
    Participant

    That 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. 🙂

    #20025
    Karen Thomas
    Participant

    Awe thanks for trying I kept failing too! God loves a trier tho 😉

    Welcome to India Jamie! 😀

    #20030
    Karen Thomas
    Participant

    Also 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! 😉

    #20032
    WC Vendors Support
    Participant

    WooCommerce 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. 🙂

    #20033
    WC Vendors Support
    Participant

    KB article updated! For a single row for text, not textarea:

    https://gist.github.com/bentasm1/9c1ea6cc4984ef283c72

    #20038
    Karen Thomas
    Participant

    Hiya 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

    #20041
    WC Vendors Support
    Participant

    Check the “Custom Fields” box. 🙂

    #20042
    Karen Thomas
    Participant

    I 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

    #20044
    WC Vendors Support
    Participant

    Oops. 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.

    #20047
    Karen Thomas
    Participant

    Yay thanks very much! 🙂

    Thanks for all your help today!

    #22522
    Karen Thomas
    Participant

    Hiya 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

    #22524
    WC Vendors Support
    Participant

    You’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-_ 🙂

    #22874
    Karen Thomas
    Participant

    Hiya 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

    #22875
    WC Vendors Support
    Participant

    If 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. 🙂

    #22890
    Karen Thomas
    Participant

    Eeeek database… I’m scared, very scared! 😉 Can you show me how I access the tables and what they’re called?
    Ta very much,
    Karen 🙂

    #22898
    WC Vendors Support
    Participant

    Hit 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!

    #23181
    Karen Thomas
    Participant

    Oh 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 🙂

    #32941
    MKC
    Participant

    Hi Concious Crafties, i was just wondering, what made you go away from using ACF?

    #32943
    Karen Thomas
    Participant

    Hi @[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

    #69197
    trish johnson
    Participant

    Thanks 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?

Viewing 30 posts - 1 through 30 (of 30 total)
  • The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.