Advertisement

Friday, 27 February 2015

How to add custom fields in user registration form in osclass.

In osclass user's registration form , you will see only few fields that's not enough for a user to register.
Osclass has functions to call the extra fields in the registration form. That can be called separately or it can be called by running a hook at last of the users registration page of osclass script.

Here i explain you the easiest way to implement the extra fields in the user registration form.First we need to download the 'requiredreg' plugin to achieve it in easy way. The name of the plugin is required registration plugins its a free plugin. we can directly download it and install in osclass and activate it.

After done the above things we just need to call a hook function in the user registration page of osclass, which is inside the theme folder user-registration.php file. 

call this hook at the end of the user-registration.php file but before submit button.

           <?php osc_run_hook('user_register_form'); ?>

    For Example:

             <?php osc_run_hook('user_register_form'); ?>
                    <div class="control-group">
                        <div class="controls">
                            <button type="submit" ><?php _e("Enregistrer", 'bender'); ?></button>
                        </div>
                    </div>
                </form>

Normally it will add the following fields inside the user registration form.

1)User Email

2)User Address

3)User Website Address

4)User Fax

5)Users country

We can remove the unwanted fields from the plugins form.php file.

How to write a cron function in osclass.

Cron job is a inbuilt functionality in osclass script. We don't have to set our own cron function in osclass. In osclass there are THREE types of cron functions available. That are given below.

1. Hourly Cron

2. Daily Cron

3.Weekly Cron

Hourly cron will be called for each hour and will execute the function every hour. Other type of crons also will work in the same way.

How to set up a cron funtion.
Create a function inside your theme folder's function.php file.

Example:
function callCronJobHourly(){

    Do something ...

}
Add this hook after the function.
osc_add_hook('cron_hourly', 'callCronJobHourly');

This is the hook function to call this function when executing hourly cron function in osclass.This means the function callCronJobHourly() will be executed hourly once inside the script. So we can have update and delete queris for expired items inside this function , it will be checked hourly and perfom the function.

If you want to run it once per day then replace the 'cron_hourly' to 'cron_daily' in the above hook. Same way will be followed for weekly cron.



Tuesday, 27 January 2015

How to list items only from specific country in osclass main page listing.

Here i have given you a way to list the items only from specific country in osclass. Normally the osclass script will list all items from all country in the main page listing, But in some cases user need to list only from one country. Given below code is used to list only from one country from the database in the osclass script.

Replace in main.php(inside your current theme folder):

Replace this code: 

     <?php if( osc_count_latest_items() == 0) { ?>

With this code     :

      <?php if( osc_count_latest_items(null, array('sCountry' => 'XX')) == 0) { ?>

Change "XX" to your country code.(its fk_c_country_code field in the table oc_t_item_location in the osclass database).