title: Only allow edit of custom field once per customer on My account > edit account in WooCommerce
body: <p>I have added a DOB field to the WooCommerce <code>My account</code> section <code>Account details</code>. The field is a date field (date of birth).</p>
  <p>The customer can edit and save. Problem is; the customer can edit and save over and over again.</p>
  <p>This is a problem because of the discount that I would like to automatically apply based on the DOB date. If the customer can edit this field more than once; they can potentially get a discount each and every day. For obvious reasons, this cannot happen.</p>
  <p>I need help in making the custom field editable ONCE and only once per customer. In wp-admin, admins can edit as they see fit - which is ok.</p>
  <p>Here is my full code so far:</p>
  <pre class="lang-php prettyprint-override"><code>add_action( 'woocommerce_edit_account_form', 'dob_on_myaccount_form' );
  function dob_on_myaccount_form() {
  
      woocommerce_form_field( 'birthday_field', array (
      'type' =&gt; 'date',
      // how do I set the format to be y-m-d as in Year, Month, Day here
      'label' =&gt; __('Date of birth', 'woocommerce' ),
      'required' =&gt; false,
      ), get_user_meta( get_current_user_id(), 'birthday_field', true ) );
  }
  
  add_action( 'woocommerce_save_account_details_errors', 'dob_on_myaccount_form_error', 10, 1 );
  function dob_on_myaccount_form_error( $args ) {
  
      if (isset( $_POST['birthday_field'] ) &amp;&amp; empty( $_POST['birthday_field'] ) ) {
  
          $args-&gt;add('error', __( 'Please provide a date of birth', 'woocommerce' ) );
      }
  }
  
  add_action( 'woocommerce_save_account_details', 'dob_on_myaccount_form_save', 10, 1 );
  function dob_on_myaccount_form_save( $user_id ) {
  
      if ( isset( $_POST['birthday_field'] ) &amp;&amp; !empty( $_POST['birthday_field'] ) ) {
  
          update_user_meta( $user_id, 'birthday_field', sanitize_text_field( $_POST['birthday_field'] ) );
      }
  }
  
  add_action( 'woocommerce_cart_calculate_fees', 'give_birthday_discount', 10, 2 );
  function give_birthday_discount( $cart, $date = 'now' ) {
  
      if ( 'now' === $date ) {
  
      $date = date( 'Y-m-d' );
  
      $discount_percentage = 10;
  
      $cart-&gt;add_fee( __( 'Birthday Discount', 'woocommerce' ), -( $cart-&gt;subtotal * $discount_percentage / 100 ));
      }
  }
  
  add_action( 'show_user_profile', 'dob_on_admin_profile', 10, 1 );
  add_action( 'edit_user_profile', 'dob_on_admin_profile', 10, 1 );
  function dob_on_admin_profile( $user ) { ?&gt;
  
      &lt;h3&gt;&lt;?php _e('Birthday','woocommerce'); ?&gt;&lt;/h3&gt;
  
      &lt;table class=&quot;form-table&quot;&gt;
  
          &lt;tr&gt;
              &lt;th&gt;&lt;label for=&quot;birthday_field&quot;&gt;&lt;?php _e('Date of Birth', 'woocommerce'); ?&gt;&lt;/label&gt;&lt;/th&gt;
              &lt;td&gt;&lt;input type=&quot;date&quot; name=&quot;birthday_field&quot; value=&quot;&lt;?php echo esc_attr(get_the_author_meta('birthday_field', $user-&gt;ID)); ?&gt;&quot; class=&quot;regular-text&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
      &lt;/table&gt;
      &lt;br /&gt;
  &lt;?php
  }
  
  add_action( 'personal_options_update', 'dob_on_admin_profile_save', 10, 1 );
  add_action( 'edit_user_profile_update', 'dob_on_admin_profile_save', 10, 1 );
  function dob_on_admin_profile_save( $user_id ) {
  
      if ( ! empty( $_POST['birthday_field'] ) ) {
      
          update_user_meta( $user_id, 'birthday_field', sanitize_text_field( $_POST['birthday_field'] ) );
      }
  }
  </code></pre>