1. Osclass Forum
  2. General
  3. Fill user table with city and zipcode when creating a new li...

Fill user table with city and zipcode when creating a new listing possible?

Started by smos, September 22, 2021, 9:02 am

  • 1

smos

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?

calinbehtuk

In your theme or in  a plugin


Code: [Select]

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');


smos

I will test this right away :-) Thank you so much for this.

Edit: Solved by adding it in theme/functions.php....  Thanks again!

  • << Last edit: September 26, 2021, 1:33 pm by smos >>
  • Quote
  • 1
Subscribe
X

Subscribe!

Subscribe to get the latest listings, updates and special offers delivered directly in your inbox.