Support

Account

Home Forums ACF PRO ACF Form on WooCommerce profile page not saving

Solved

ACF Form on WooCommerce profile page not saving

  • Hi Guys

    I have ACF pro on my site and created a field group for the user profile which saves fine from the admin profile page. The profile on the front end is managed via WooCommerce so I added another endpoint for the field group I created. This displays the form OK, and the acf_form_head() is appearing and the hidden field values seem to be populated with real data, but clicking submit refreshes the page but the data is not updating.

    So to modify WooCommerce I followed this guide: https://rudrastyh.com/woocommerce/my-account-menu.html
    I added the menu item (Member Directory) and then this code to create the endpoint and put the form into it:

    
    add_action( 'init', 'lucas_add_endpoint' );
    function lucas_add_endpoint() {
     	add_rewrite_endpoint( 'member-directory', EP_PAGES );
    }
    
    add_action( 'woocommerce_account_member-directory_endpoint', 'lucas_my_account_endpoint_content' );
    function lucas_my_account_endpoint_content() {
    	echo "<h1>Member Directory</h2>".do_shortcode('[my_acf_user_form field_group="36886"]');
    }
    

    I embedded the form following the instructions here: https://usersinsights.com/acf-user-profile/

    
    function my_acf_user_form_func( $atts ) {
     
      $a = shortcode_atts( array(
        'field_group' => ''
      ), $atts );
     
      $uid = get_current_user_id();
      
      if ( ! empty ( $a['field_group'] ) && ! empty ( $uid ) ) {
        $options = array(
          'post_id' => 'user_'.$uid,
          'field_groups' => array( intval( $a['field_group'] ) ),
          'return' => add_query_arg( 'updated', 'true', get_permalink() )
        );
        
        ob_start();
        
        acf_form( $options );
        $form = ob_get_contents();
        
        ob_end_clean();
      }
      
        return $form;
    }
     
    add_shortcode( 'my_acf_user_form', 'my_acf_user_form_func' );
    
    //adding AFC form head
    function add_acf_form_head(){
        global $post;
        
      if ( !empty($post) && has_shortcode( $post->post_content, 'my_acf_user_form' ) ) {
            acf_form_head();
        }
    }
    add_action( 'wp_head', 'add_acf_form_head', 7 );
    

    Looking at the source of the page, the HTML looks OK:

    <h1>Member Directory</h2>		
    		<form id="acf-form" class="acf-form" action="" method="post">
    			
    			<div id="acf-form-data" class="acf-hidden">
    				<input type="hidden" id="_acf_screen" name="_acf_screen" value="acf_form" />
    				<input type="hidden" id="_acf_post_id" name="_acf_post_id" value="user_2015" />
    				<input type="hidden" id="_acf_nonce" name="_acf_nonce" value="704192003c" />
    				<input type="hidden" id="_acf_validation" name="_acf_validation" value="1" />
    				<input type="hidden" id="_acf_ajax" name="_acf_ajax" value="0" />
    				<input type="hidden" id="_acf_changed" name="_acf_changed" value="0" />
    				<input type="hidden" id="_acf_form" name="_acf_form" value="bUlEZDlESVlncWs3YVh4QmlVeFd2dGc1Sjl0dXp1R3hQSDg2WldoMGpkMGppSXZLQ25rQ0w5aTFtVldFR1FycFMwelNnZU5hRWlDN1lsL2lKUG5idW9uTjZRdUphY1RzaXZueWltdkZrR042eURYMFYxbmdjWkw0ejQrR2x5TFBSeU1leXB4aEdxN0RrakMyallzWTlSUk0xamZrbDdwZnN0aENEQWNZelhDQng2TjNPMDU1YUJIeElLOTZNUDF5Q0VqdVhHM0VtOHBGWmQ0QVVrKzFiKzRSa1VIUFRPRmF4dlBwekloSFhzUzd4MjFBc0pHQ1ZYa1FPZFEyNHZQYkpma0tyRGpKRTQwWWIxVXordlk5RU5FeE1DZDhqSSszSW4zN0JHempReEcyZFlWUjl2V051a1h6OGl4NXBjRjBmaDgzUlpscTgzRVM0Q1Ava295b01YcnVOcG9DYms5QTBrenh4cUxLbGtvdnMrRDI1d3l5SDRqRFplTDYrZlVjWlZDOU1LSjgxVjFXT3VaTG9KWTFJMG91elpXNWZMQ242NFQrK252TnBxaVF5M0xnQWZlblBMUXpTVkJ4S3BhQ3YreVFobVZxeFhXaUwwWmJOYnBxVG8vaTNENXgreUdSdlRleUNHM2s0Y0wyeCs1c1NaYWpWRHBsUlZsRVV5N1BSQ3ZMNHVhYkw3YnNneDlBcXFzY1RSYTZMSldPS1JkL3pFelNEOHVzRUZ0NmZkMkZBWHUwV3IrRHpONjRJbFpud3B5RWxzc3laSXppQXcySUVuU3dFamkrZ09UTW9vZnJjaExvazBkMU53cXRVNzIrTU5kZWZLdkVPeVZZMVdNRUhXS0V0MmREc0Z5YlZoT2ZlTFZUK1RCQlJoU3AxdEtvd2dxMUZ4ME1vUnlWNHgrOUpkRE5oR1Z6M1NoOVVuNGliQVllVDlDa2RQYUt1dEFwbjNwMDVXM1YxR2IxRFJpU29xN01GYm9wL25kUmdvYm9vZ2U5a0NxeVZKQjNCcXV2YVYvK0VrSW1PN2pqK1A5RFFoRXVOMjVxcEhzQ3JJWS9sdHFRL29YNkZYOGsxRk1YZnZpWnpJUVV6UEp6MWxNL2pnU2trN200STVpZDREemczdGhYVFVXczNCbGkrQmJMM2gzd245amJBRVM1WThNZkxUc1gvR0VOdVoxZ2wrckxjOWlNUEJGRTdTMUpKeERtSU5RTE16N1JLanRORkV4eG9HOXJGb3lETGJiQ0k3alZ0eWk0Z2J1dkZML0h2ejVLRkZNazR1OENpNDRpdW44aHJlZmxRdXJTMnYrazQ1RE5wU29mRy9qamNUbWtoM1VyYldxQkJPZ1pSUlFRUUNseGxkS2lETlgyZVZNeDNjRmgwMUh3dlE9PTo6kVFgR2JMuj6/AVizkx9EtA==" />
    					</div>
    

    This is followed by all the form fields etc. The <form> isn’t embedded inside another form tag. So it should be working, it submits OK and reloads the page, there’s a user ID in the form fields…

    Can anyone suggest where to start looking or how to debug this issue?

    Cheers

  • Same problem here. Did you find the solution @pr0fess0r? thank you in advance 🙂

  • Sadly not! I went a different way 🤷‍♂️

  • oh… 🙁
    thanks for your answer @pr0fess0r. i will keep investigating!
    <3

  • I have changed the line:
    if ( !empty($post) && has_shortcode( $post->post_content, ‘my_acf_user_form’ ) ) {

    for this other:
    if ( !empty($_POST) && $_POST[“_acf_screen”] == “acf_form” ) {

    and now it seems it works!

  • Oh nice, well done!

  • Thanks for the solution @ciclick. I was experiencing a similar issue, your suggestion fixed the saving issue. Much appreciated!

    However whenever I update the ACF fields inside a custom tab under the my-account page, it jumps back to the my-account dashboard. This occurs ever since I’ve implemented that line of code.

    @pr0fess0r Did you experience similar issues perhaps? If so, how did you resolve this?

    Many thanks!

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

You must be logged in to reply to this topic.