Fill user table with city and zipcode when creating a new listing possible?
on :September 22, 2021, 9:02 am #525
Hello,
I was wondering if osclass can insert country, city and zip code when creating a new listing.
At this time when a new user is created with email table user gets filled with name email etc....
When the same user is posting a new listing, the form gets pre-filled with his name, phone and all other fields.
Now when a user logs in with FB or Google those data isn't set yet in user table so when that user is posting a new listing they have to fill in the form completely again and again because data is not kept in user table unless they fill in there user profile page (which most of them don't do). Probably this is possible, only thing is how to start..... custom worker maybe?
Re: Fill user table with city and zipcode when creating a new listing possible?
on :September 23, 2021, 6:42 pm #526
In your theme or in a plugin
function after_post_item_hook($item) {
//Get user id
$userId = $item['fk_i_user_id'];
if ($userId > 0) {
$userClass = User::newInstance();
$user = $userClass->findByPrimaryKey($userId);
$updateLocation = (!empty($user)) ? ((empty($user['s_region'])) ? true : false) : false;
if ($updateLocation) {
$array = array(
's_country' => $item['s_country'],
'fk_c_country_code' => $item['fk_c_country_code'],
's_region' => $item['s_region'],
'fk_i_region_id' => $item['fk_i_region_id'],
's_city' => $item['s_city'],
'fk_i_city_id' => $item['fk_i_city_id'],
's_city_area' => $item['s_city_area'],
's_address' => $item['s_address']
);
$userClass->update($array, array('pk_i_id' => $userId));
}
}
}
osc_add_hook('posted_item', 'after_post_item_hook');
Re: Fill user table with city and zipcode when creating a new listing possible?
on :September 24, 2021, 12:23 pm #527
I will test this right away :-) Thank you so much for this.
Edit: Solved by adding it in theme/functions.php.... Thanks again!