Skip to content

Commit

Permalink
🔧 chore(Installer.php): add schedule_cron_jobs() method to Installer …
Browse files Browse the repository at this point in the history
…class for scheduling recurring cron jobs
  • Loading branch information
nurul-umbhiya committed Nov 10, 2023
1 parent 7ae4116 commit 7db4582
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions includes/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function do_install() {
$this->create_reverse_withdrawal_base_product();
$this->product_design();
$this->add_store_name_meta_key_for_admin_users();
$this->schedule_cron_jobs();

// does it needs any update?
if ( dokan()->has_woocommerce() && dokan()->upgrades->is_upgrade_required() ) {
Expand Down Expand Up @@ -80,6 +81,34 @@ public function add_store_name_meta_key_for_admin_users() {
}
}

/**
* Schedule cron jobs
*
* @since DOKAN_SINCE
*
* @return void
*/
private function schedule_cron_jobs() {
if ( ! function_exists( 'WC' ) || ! WC()->queue() ) {
return;
}

// schedule daily cron job
$hook = 'dokan_daily_midnight_cron';

// check if we've defined the cron hook
$cron_schedule = as_next_scheduled_action( $hook ); // this method will return false if the hook is not scheduled
if ( ! $cron_schedule ) {
as_unschedule_all_actions( $hook );
}

// schedule recurring cron action
$now = dokan_current_datetime()->modify( 'midnight' )->getTimestamp();
WC()->queue()->schedule_cron( $now, '0 0 * * *', $hook, [], 'dokan' );

// add cron jobs as needed
}

/**
* Adds plugin installation time.
*
Expand Down

0 comments on commit 7db4582

Please sign in to comment.