I have a form with the a input name=”first_name” and i want to put this information on the first_name of the current user, so when do this form is submited and i try to var_dump the object, i see the first_name is empty. Here is my code:

      $wc_current_user = WC()->customer;

      if ( isset($_POST['first_name']) ) {
           $wc_current_user->set_first_name($_POST['first_name']);

           $wc_current_user->save();
      }
      var_dump($wc_current_user);

my input field is :

       <form class="woocommerce-account-information" action="" method="post">

           <label>First Name</label>
           <input type="text" name="first_name" value="<?php echo $wc_current_user->get_first_name()?>"/>


           <button type="submit">SAVE</button>
      </form>

Do you can help me to fix it, save this data from the form to the first_name property in the current user instance object.

Read more here: Why this form is not saving data on Woocommerce CRUD Object 3.0?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: