Support

Account

Home Forums ACF PRO Append Fields to WooCommerce Register Form Reply To: Append Fields to WooCommerce Register Form

  • I don’t think that there is any way to do this, but to be honest, I don’t know.

    You would somehow need to capture the user ID that was just created and before ACF tries to save the values.

    I don’t know if any of this will work.

    use "new_user" for the post ID in your form.

    https://www.advancedcustomfields.com/resources/acf-pre_save_post/

    
    // i'm using a class here so I can store a value in one action/filter
    // and retrieve it in a different action/filter
    // you could also do this using a global variable
    class my_custom_acf_save_user_form {
      
      private $user_id = false; // will store the user id just saved
    
      public function __construct() {
        add_action('user_register', array($this, 'user_register', 10, 1);
        add_filter('acf/pre_save_post', array($this, 'pre_save_post', 10, 1);
      }  // end __construct
    
      public function user_register($user_id) {
        // capture the id of the user just created
        $this->user_id = $user_id;
      } // end user_register
    
      public function pre_save_post($post_id) {
        if ($post_id == 'new_user' && $this->user_id) {
          $post_id = 'user_'.$this->user_id;
        }
        return $post_id;
      } // end pre_save_post
    
    } // end class
    
    new my_custom_acf_save_user_form();