admin管理员组文章数量:1312858
We are looking for a way to add Advanced Custom Fields data to a user / subscriber after they have purchased a product (Woocommerce). The subscriber should be able to edit these fields on the frontend and save to their own account. We have been using Buddypress's XProfile fields to handle this but isn't ideal for what we need to do.
We know you can use ACF to add user fields but how to then bring those fields to the frontend?
We are looking for a way to add Advanced Custom Fields data to a user / subscriber after they have purchased a product (Woocommerce). The subscriber should be able to edit these fields on the frontend and save to their own account. We have been using Buddypress's XProfile fields to handle this but isn't ideal for what we need to do.
We know you can use ACF to add user fields but how to then bring those fields to the frontend?
Share Improve this question asked Feb 3, 2019 at 5:47 BenjaminBenjamin 1852 silver badges14 bronze badges 1- Here's a nice little tutorial on the ACF way of doing that. usersinsights/acf-user-profile – mrben522 Commented Feb 6, 2019 at 19:21
2 Answers
Reset to default 3ACF has a built in way to do this. Its acf_form(). Essentially it lets you build a form on the frontend that will update your custom fields.
Here is a basic example from their site. Note the use of acf_form_head(), which is needed to actually save the data.
<?php acf_form_head(); ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php /* The loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php acf_form(array(
'post_id' => 123,
'post_title' => false,
'submit_value' => 'Update the post!'
)); ?>
<?php endwhile; ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
As stated in one of the comments, this tutorial walks you through basically what you are trying to do.
You can use ACF on the frontend in similar way
$user_id = 'user_' . $user->ID . '';
$field = get_field( 'some_field', $user_id );
Please note that some settings must be set
Than you can use AJAX to update necessary fields from the frontend
$post_id = $_POST['post_id'];
$some_post_data = $_POST['some_post_data'];
$field_ref = get_field_reference('some_field', $post_id);
$field = get_field('some_field', $post_id);
$value = $field;
var_dump($value);
//$value modification
update_field($field_ref, $value, $post_id);
本文标签: Add user custom fields and make editable on frontend
版权声明:本文标题:Add user custom fields and make editable on frontend 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741853945a2401231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论