• Resolved PleasantlyOdd

    (@pleasantlyodd)


    Hello,

    I’m trying to add custom fields to the woo commerce user account information back end, I’ve managed to get the fields to show up, but there not saving correctly, can anyone see where I’ve gone wrong?

    ____

    I’m assuming I’ve written something wrong in the ‘function my_woocommerce_save_account_details’ which is causing my field not to save any changes.

    <?php
    
    add_action( 'woocommerce_edit_account_form', 'my_woocommerce_edit_account_form' );
    add_action( 'woocommerce_save_account_details', 'my_woocommerce_save_account_details' );
    
    function my_woocommerce_edit_account_form() {
    
      $user_id = get_current_user_id();
      $user = get_userdata( $user_id );
    
      if ( !$user )
        return;
    
      $twitter = get_user_meta( $user_id, 'twitter', true );
      $url = $user->user_url;
    
      ?>
    
      <fieldset>
        <legend>Store ID (Retailers Only)</legend>
        <p>If your a stockist of the real effect, enter your store ID here.</p>
        <p class="form-row form-row-thirds">
          <label for="StoreID">StoreID:</label>
          <input type="text" name="StoreID" value="" class="input-text" />
        </p>
      </fieldset>
    
      <?php
    
    }
    
    function my_woocommerce_save_account_details( $user_id ) {
    
      update_user_meta( $user_id, 'StoreID', htmlentities( $_POST[ 'StoreID' ] ) );
    
      $user = wp_update_user( array( 'ID' => $user_id, 'StoreID' => esc_url( $_POST[ 'url' ] ) ) );
    
    }
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Woocommerce Custom User Fields’ is closed to new replies.