Home Forums WC Vendors Pro Support Howto: Add ACF fields to frontend shop edit

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 24 posts - 1 through 24 (of 24 total)
  • Author
    Posts
  • #10739
    Ben Lumley
    Participant

    Thought I’d share:

    add_action(‘wcvendors_settings_after_shop_name’, ‘wcv_save_acf_fields’);
    function wcv_save_acf_fields() {
    acf_form_head();
    }

    add_action(‘wcvendors_settings_after_seller_info’, ‘wcv_add_acf_fields’);
    function wcv_add_acf_fields() {
    acf_form(array(
    ‘form’ => false,
    ‘return’ => false,
    ‘post_id’ => WCVendors_Pro_Vendor_Controller::get_vendor_store_id( get_current_user_id() )
    ));
    }

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

    Also possible via acf_form to alter the markup a bit to make it fit your theme.

    #10762
    WC Vendors Support
    Participant

    Thanks Ben, much appreciated. I’ve converted the code into a KnowledgeBase article and posted it publicly here:

    https://www.wcvendors.com/knowledgebase/pro-adding-advanced-custom-fields-acf-support/

    Feel free to make as many snippets as you’d like and share them! πŸ™‚

    #14877
    Jan-Philipp Wittrin
    Participant

    Hi @benlumley and Ben, hi Community

    thank you for sharing this piece of code. It is really great!!!

    I can get the ACF fields to work inside the vendor settings, I can also echo text acf fields in the store-header template.

    But for some reason I can’t get the image ACF field to display in the store header.

    I tried it with this one and many other ways…

    
    <?php
    $img = wp_get_attachment_image_src( get_post_meta( $store_id, 'representive_image_of_shop',true ), array( 150, 150 	) );?>
    
    <img src="<?php echo $img[0];?>" alt="" class="" />

    Any ideas would be very much appreciated.

    Cheers,

    jp

    #14893
    Jan-Philipp Wittrin
    Participant

    Ok. Simple, once you know it. It was a caching problem of ACF. Here I found the answer: http://support.advancedcustomfields.com/forums/topic/text-field-that-should-show-content-displays-boolfalse/

    So I created a new ACF image field and user the code above and now it is working.

    And this is really amazing, because the interplay of ACF Frontend Forms and WC Vendors opens up a whole new world…

    Thank you so much @benlumley for this gold piece of code.

    #14960
    Ben Lumley
    Participant

    Glad it helped.

    #22894
    Mikaelfs
    Participant

    Hey guys,

    I got this to work earlier, but not anymore. Is there any change in the code after the 1.2 update?

    Thanks for any help πŸ˜‰

    #22895
    WC Vendors Support
    Participant

    If there is let me know, happy to update the KB.

    #22934
    Mikaelfs
    Participant

    Hi Ben,

    I got it to work, but I bet it’s better a “pro” makes a best practice πŸ™‚ I didn’t use the Pro Controller. But atleast it displayed the fields and save them to the backend.

    This is the code:

    add_action('wcvendors_settings_after_seller_info', 'wcv_add_acf_fields');
    function wcv_add_acf_fields() {
        acf_form( array(
            'form' => false,
            'return' => false,
            'post_id' => 'user_'.get_current_user_id() 
        ) );
    }

    Also, I’ve had a problem from the start that after I save the Store settings the page reloads with only the store name displayed (but of course settings are saved). I’m attaching image for reference. Is this something you’ve seen before?

    #23004
    WC Vendors Support
    Participant

    I’m not entirely sure what I’m looking at in the screenshot — Are you saying that the only field visible after you save the store settings page is the store name and nothing else?

    If that’s the case, your custom template is probably causing a PHP error and not loading the rest of the page because it’s died. Your error_log would show you the error in which file and which line and the type of error it is of course.

    Let me know!

    Ben

    #23389
    Mikaelfs
    Participant

    Hi Ben,

    There’s no error message for this error in the log…
    I deleted my own template and tried it with the original, and I still get the same error.
    Loading of the page stops at after the store name..

    BR
    Mikael

    #23393
    WC Vendors Support
    Participant

    I’m curious if your memory limit is too low in WordPress. That’s about the only thing that would cause a page to stop loading halfway. Even then still, it would generate an error in the error_log.

    #23409
    Mikaelfs
    Participant

    Strange..

    Memory Limits is 256Mb,
    Last error message is from the 5th

    #23411
    WC Vendors Support
    Participant

    In this screenshot:

    https://www.wcvendors.com/members/mikaelfs/media/531/

    How are you clicking Save if you don’t see a save button?

    #23412
    Mikaelfs
    Participant

    Ohh, sorry. Wasn’t clear.

    The pages loads but when I save it stops to load there.
    The changes is saved.
    When I reload (f5) the page it’s still not loading.
    If I click the tab (settings) it reloads and works again.

    #23413
    WC Vendors Support
    Participant

    That’s pretty funky. Do you have any functions.php code that is changing fields at all? Sounds like something is crapping out the forum in a custom fashion.

    Feel free to START A NEW THREAD about this, and then add your site url, admin user, admin pass in the new threads first reply set as a private reply. If you post that here, since you arent the original poster in this thread, the owner of this thread can read your login details too.

    #35612
    MKC
    Participant

    Hi Guys – how are you addressing this in ACF in the locations area (to add the fields to the vendor?)

    #36593
    MKC
    Participant

    A small edit to the original form, I’ve managed to get this to work so that the ACF field data is specific to a particular ACF field group, not just “any” field group that is user form edit/new .. . . and more importantly the form field on the front end actually saves the data back to teh vendor profile.

    /* – Courtesy of Ben Lumley – https://www.wcvendors.com/help/topic/howto-add-acf-fields-to-frontend-shop-edit/
    *
    * 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_settings_after_shop_name’, ‘wcv_save_acf_fields’);
    function wcv_save_acf_fields() {
    acf_form_head();
    }

    add_action(‘wcvendors_settings_after_seller_info’, ‘wcv_add_acf_fields’);
    function wcv_add_acf_fields() {
    acf_form( array(
    ‘post_id’ => ‘user_’.get_current_user_id(), // $user_profile,
    ‘field_groups’ => array(5720), (Note from me, this array number is the number of the form, so you only pull that form number)
    ‘form’ => true,
    ‘return’ => false,
    ‘submit_value’ => ‘Update’
    ) );
    }

    // if you have media upload fields (file/image), they won’t work, and further, the existing branding uploaders for icon etc break.
    // this is because acf alters the uploader init to pass a post_id, and vendor users don’t have ‘edit_post’ capabilities, assume you guys are handling this somewhere else
    // this snippet adds a filter in so that if we are trying to ‘edit_post’ on our own published vendor store, it will be allowed – restoring media upload.

    add_filter(‘user_has_cap’, ‘wcv_vendor_has_cap’, 4, 99);
    function wcv_vendor_has_cap($allcaps, $caps, $args, $user) {
    if ($args[0] == ‘edit_post’) {
    $post = get_post($args[2]);
    if ($post->post_type == ‘vendor_store’ && $post->post_author == $user->ID) {
    $allcaps[‘edit_published_posts’] = true;
    }
    }
    return $allcaps;
    }

    #40113
    Rustan
    Participant

    I have two set of custom fields groups, how can I specify which one to use?

    #57568
    Maksim
    Participant

    How do you put ACF fields inside the vendor settings? Any example code please?

    #57569
    Maksim
    Participant

    I havo also the same error as @MIKAELFS. When i click SAVE CHANGES, all field and button dissapear. Only Store name in on the scrren.

    The second problem is when vendor enter some info in extra field and save it, this info not appear in Users->edit user fields. They just stay empty.

    #57577
    Anna
    Member

    Hello,
    No idea- I do not use that plugin.
    We encourage users to use our code available in WC Vendors Pro to add or modify fields for the product and settings forms.
    Please see these KB articles:
    https://www.wcvendors.com/kb/adding-a-custom-field-for-products/
    https://www.wcvendors.com/kb/custom-fields-to-shop-settings-page/

    #57796
    Maksim
    Participant
    #58689
    Kashif
    Participant

    Hello,
    I am using wc vendors Pro plugin.
    I am editing the code of product-edit.php. I want to have a field for uploading file that contains information about the product.
    <?php
    WCVendors_Pro_Form_Helper::file_uploader( array(
    ‘header_text’ => __(‘File uploader’, ‘wcvendors-pro’ ),
    ‘add_text’ => __(‘Add file’, ‘wcvendors-pro’ ),
    ‘remove_text’ => __(‘Remove file’, ‘wcvendors-pro’ ),
    ‘image_meta_key’ => ‘_wcv_custom_product_file1’, // Must match meta key used in line 3
    ‘save_button’ => __(‘Add file’, ‘wcvendors-pro’ ),
    ‘window_title’ => __(‘Upload a file about product’, ‘wcvendors-pro’ ),
    )
    );
    ?>
    ………..
    The above code is adding a file to admin. But when I try to access that file on front end with this code
    <?php echo get_post_meta($post->ID, ‘_wcv_custom_product_file1’,true); ?>
    Its not displaying the file Path.
    Please guide me as I am working on this issue for two days.
    For Image its working Fine. I used the following code for image
    <?php

    $sample_photo_graph = get_post_meta($object_id, ‘_wcv_custom_product_sample_photo’, true );

    WCVendors_Pro_Form_Helper::file_uploader( array(
    ‘header_text’ => __(‘File uploader’, ‘wcvendors-pro’ ),
    ‘add_text’ => __(‘Upload Sample’, ‘wcvendors-pro’ ),
    ‘size’ => ‘mediam’,
    ‘remove_text’ => __(‘Remove Sample’, ‘wcvendors-pro’ ),
    ‘image_meta_key’ => ‘_wcv_custom_product_sample_photo’,
    ‘save_button’ => __(‘Upload Sample’, ‘wcvendors-pro’ ),
    ‘window_title’ => __(‘Select an Image’, ‘wcvendors-pro’ ),
    ‘value’ => $sample_photo_graph,
    )
    );
    ?>

    #66930
    Helpende Hand
    Participant

    Hi

    What action hook can i use to display it in the “add new product” page? /product/download/edit/
    Thank you

    —I manage to get it to work.

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