Support

Account

Home Forums Front-end Issues Show ACF field in WC Vendor Pro "Add Product"

Solving

Show ACF field in WC Vendor Pro "Add Product"

  • Hey,

    I am would like to show ACF True/False field and maybe a dropdown or text field on WC Vendor’s “Add Product” page.This plugin allows user to apply to become a vendor and upload product in the frontend and I would like to add few extra option, this could easily be done in the backend where I create a field group and assign it to “Post Type = Product” but now I would like to have another condition where the ACF field option is also shown in the Vendor’s Add Product page so the vendors have the same field option as the admin. I have tried in the “Field Group > Location > Post Type = Product or Current User = Viewing from frontend” this also does not show the ACF field in the frontend.

    Really appreciate the help.
    Regards

  • I have managed to show ACF field on “Add Product” page for WC Vendors.

    This is the code I have got from WC Vendor’s support forum.

    and just bit of modification in the hook, instead of add_action(‘wcvendors_settings_after_shop_name’, ‘wcv_save_acf_fields’); hook I used add_action('wcvendors_after_product_form' to save the form. and to display field original code : add_action(‘wcvendors_settings_after_seller_info’, ‘wcv_add_acf_fields’); and I have replaced it with add_action('wcv_after_product_details' to display it on Add product page. The full code is below:

    /*
     *- Courtesy of Ben Lumley -
     * https://www.wcvendors.com/help/topic/howto-add-acf-fields-to-frontend-shop-edit/
     *
     * https://docs.wcvendors.com/knowledge-base/adding-advanced-custom-fields-acf-support/
     *
     * This will display + save any custom fields applicable to the vendor_shop in question.
     * Second one displays the fields, you can adjust the action it’s attached to in order
     * to move the fields (see templates/dashboard/store-settings.php in the pro plugin for
     *  possible actions). You could also split and display different fields in different
     * places – see the docs for acf_form, you can select single/groups of fields.
     * http://www.advancedcustomfields.com/resources/acf_form/
     * Also possible via acf_form to alter the markup a bit to make it fit your theme.
     *
     * This code is not supported by WC Vendors, use at your own risk and at your own discretion.
    */
    
    add_action('wcvendors_after_product_form', function () {
        acf_form_head();
    });
    
    add_action('wcv_after_product_details', function () {
    
        acf_form(
            [
                'post_id' => 'user_' . get_current_user_id(),
                'form' => false,
                'return' => false
            ]
        );
    
    });

    the field shows now, but the problem is it’s not saving the ACF value. any idea why it is not saving 🙁

  • 1) ACF form head must appear before any other page output, before ‘get_header()’. Using the hook you are using the html is already started before ‘acf_form_head()’ is called.

    2) In order for the ACF fields to submit they must appear inside of the `<form></form>’ tags of the other form. I can’t tell by looking at your code if this is the case or not.

  • Thank you very much John,

    Will implement on what you have advice and check 🙂

    Appreciate your help. 🙏🏽

  • Hello Naveet!

    Have you succeeded in making this work? I will need to do the same thing on a client site and if you’ve got it working it would be great if you could share the final code 🙂

    Thanks!

  • Hey @webfocusdesign

    Sorry for the late reply. Unfortunately, I could not make it work with ACF Pro which I would like and still looking for a way to implement it with ACF Pro. Tried following this:
    https://support.advancedcustomfields.com/forums/topic/acf-wc-vendors-front-dashboard/

    did not work for me.

    But I did use an alternative method of using WC Vendor Pro custom field, that did work but it is not very dynamic as ACF Pro

    https://docs.wcvendors.com/knowledge-base/adding-a-custom-field-for-products/

    and they have a few fields you can choose from:
    https://docs.wcvendors.com/knowledge-base/form-helper/

    It seems the new update has a lot more option when I was trying to implement the field a few months ago.

    Hope I was able to help.

    Regards,

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.