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.
Thank you to all of our customers!
- This topic has 23 replies, 10 voices, and was last updated 6 years, 4 months ago by
Helpende Hand.
-
AuthorPosts
-
October 13, 2015 at 7:07 am #10739
Ben Lumley
ParticipantThought 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.
October 13, 2015 at 11:36 am #10762WC Vendors Support
ParticipantThanks 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! π
November 9, 2015 at 10:18 am #14877Jan-Philipp Wittrin
ParticipantHi @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
November 9, 2015 at 11:54 am #14893Jan-Philipp Wittrin
ParticipantOk. 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.
November 10, 2015 at 6:59 am #14960Ben Lumley
ParticipantGlad it helped.
February 3, 2016 at 7:29 pm #22894Mikaelfs
ParticipantHey 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 π
February 3, 2016 at 8:01 pm #22895WC Vendors Support
ParticipantIf there is let me know, happy to update the KB.
February 4, 2016 at 2:16 am #22934Mikaelfs
ParticipantHi 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?
February 4, 2016 at 4:14 pm #23004WC Vendors Support
ParticipantI’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
February 8, 2016 at 9:21 am #23389Mikaelfs
ParticipantHi 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
MikaelFebruary 8, 2016 at 10:35 am #23393WC Vendors Support
ParticipantI’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.
February 8, 2016 at 11:12 am #23409Mikaelfs
ParticipantStrange..
Memory Limits is 256Mb,
Last error message is from the 5thFebruary 8, 2016 at 11:18 am #23411WC Vendors Support
ParticipantIn this screenshot:
https://www.wcvendors.com/members/mikaelfs/media/531/
How are you clicking Save if you don’t see a save button?
February 8, 2016 at 11:21 am #23412Mikaelfs
ParticipantOhh, 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.February 8, 2016 at 11:23 am #23413WC Vendors Support
ParticipantThat’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.
June 26, 2016 at 4:06 am #35612MKC
ParticipantHi Guys – how are you addressing this in ACF in the locations area (to add the fields to the vendor?)
July 8, 2016 at 12:43 am #36593MKC
ParticipantA 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;
}August 15, 2016 at 5:05 pm #40113Rustan
ParticipantI have two set of custom fields groups, how can I specify which one to use?
February 25, 2017 at 7:56 am #57568Maksim
ParticipantHow do you put ACF fields inside the vendor settings? Any example code please?
February 25, 2017 at 9:04 am #57569Maksim
ParticipantI 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.
February 25, 2017 at 10:01 am #57577Anna
MemberHello,
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/February 28, 2017 at 9:11 am #57796Maksim
ParticipantI put this lines to my function.php:
http://docs.wcvendors.com/knowledge-base/adding-advanced-custom-fields-acf-support/I add this settings:
https://dl.dropboxusercontent.com/s/t654rknuoelnbms/shot_170228_152806.jpgSo i see my field (google map) in users settings:
https://dl.dropboxusercontent.com/s/hzxm4jjtjioy4b0/shot_170228_152905.jpgBut don see it on vendor setings page:
https://dl.dropboxusercontent.com/s/5su3foj2ki92hdx/shot_170228_153011.jpgCan someone help me to solve this problem?
March 9, 2017 at 2:21 pm #58689Kashif
ParticipantHello,
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,
)
);
?>-
This reply was modified 6 years, 6 months ago by
Kashif.
June 1, 2017 at 9:28 am #66930Helpende Hand
ParticipantHi
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.
-
This reply was modified 6 years, 6 months ago by
-
AuthorPosts
- The forum ‘WC Vendors Pro Support’ is closed to new topics and replies.