title: Updating Wordpress Database on Customer Account Creation
body: <p>I'm running a WooCommerce shop with multi-vendor support. Customers can checkout or message sellers without logging in (they have to enter an email address), but I want this to backdate their orders/enquiries when they create an account.</p>
  
  <p>I'm using the WooCommerce function wc_update_new_customer_past_orders() and the hook woocommerce_created_customer for linking past orders with their new account which is working. But can't get this to work for the enquiries.</p>
  
  <p>The code i'm using is below, works well using the wp_footer hook on page refresh, but not on woocommerce_created_customer. Any ideas?</p>
  
  <pre><code>    function link_past_enquiries_at_registration( ) {
        global $wp, $WCFM, $wpdb;
        $linked  = 0;
        $user_id = get_current_user_id();
        $customer  = get_user_by( 'id', $user_id );
        $customer_email  = $customer-&gt;user_email;
        $enquiry_query = "SELECT * FROM {$wpdb-&gt;prefix}wcfm_enquiries AS commission";
          $enquiry_query .= " WHERE 1 = 1";
          $enquiry_query .= " AND `customer_id` = 0";
          $enquiry_query .= " AND `customer_email` = '$customer_email'";
          $enquiry_query .= " ORDER BY commission.`ID` DESC";
  
          $wcfm_inqueries = $wpdb-&gt;get_results( $enquiry_query );
  
         if( !empty( $wcfm_inqueries ) ) {
          $wpdb-&gt;update( $wpdb-&gt;prefix . 'wcfm_enquiries', array('customer_id'=&gt;$user_id), array('customer_email'=&gt;$customer_email, 'customer_id'=&gt;0) );
          $linked++;
        }
      }
      add_action( 'woocommerce_created_customer', 'link_past_enquiries_at_registration' );
  </code></pre>