How to use wp cron job to run a function

First of all you have to remember how WP cron works. The action will trigger when someone visits your WordPress site, if the scheduled time has passed. So if your site isn’t very crowded at 3am, the cron job won’t start exactly at 3am. (You should use real cron if you really need to run it exactly at 3am).

To schedule an event at 3am every day you can use this code:

function do_this_daily_after_3am() {
    // do something every day after 3am
}
add_action('my_daily_event', 'do_this_daily_after_3am');


function my_activation() {
    if ( !wp_next_scheduled( 'my_daily_event' ) ) {
        $next3am = ( date('Hi') >= '0300' ) ? strtotime('+1day 3am') : strtotime('3am');  // you can calculate it in any way you want

        wp_schedule_single_event( $next3am, 'my_daily_event');
    }
}
add_action('wp', 'my_activation');