I am trying to figure out how to add user information and specific meta data to a separate table through PHP. I would prefer to do this when a user posted to the wp_users
and wp_usermeta
table. I am using the WooCommerce Auction plugin and the Salient theme.
Also if I made a PHP file that ran a query to pull the data and then insert, where is a good place I can call that function to ensure the table is up to date?
This is the function I've created.
add_action('user_register', 'save_to_donors',10,1);
function save_to_donors( $user_id ) {
$single = true;
$user_email = get_userdata($user_id);
$fn= get_user_meta($user_id, 'first_ name', $single );
$ln= get_user_meta($user_id, 'last_name', $single );
$em= $user_email->user_email;
$ph= get_user_meta($user_id, 'billing_phone', $single );
$ad= get_user_meta($user_id, 'billing_address_1', $single );
$ci= get_user_meta($user_id, 'billing_city', $single );
$st= get_user_meta($user_id, 'billing_state', $single );
$zi= get_user_meta($user_id, 'billing_postcode',$single );
$do= get_user_meta($user_id, '_money_spent', $single );
$sql = "INSERT INTO donors (user_id,first_name,last_name,email," .
"phone,address,city,state,zip,amount_donated)".
"VALUES('$user_id','$fn','$ln','$em','$ph','$ad','$ci','$st','$zi','$do')";
$result = mysqli_query($wpdb, $sql) or die('Write Error!');
}