skip to Main Content

I am trying to hook into the woocommerce_order_status_changed action and add a single event to the wp cron to execute immediately (so that the request-response cycle is not blocked):

add_action('woocommerce_order_status_changed', 'on_new_status', 10, 3);
add_action('send_new_status_custom_hook', 'logic_on_new_status', 10, 2);
function on_new_status($order_id, $from, $to){
  wp_schedule_single_event(time(), 'send_new_status_custom_hook', array($from, $to));
}
function logic_on_new_status($first, $second){
  // code
}

The event is added to the cron (I can see it using a plugin), but not executed. When I click on “execute” manually, it is executed.

What could the problem be?

I am using WordPress 5.3.2.

Thanks!

3

Answers


  1. Chosen as BEST ANSWER

    I've found the solution! The issue was caused by my firewall settings...

    They were blocking the loopback which wp-cron requires to function properly.

    Installing this plugin: https://wordpress.org/plugins/wp-crontrol/ showed me the error message "cURL error 28".

    From there, I was able to figure it out.


  2. Hello you are using cron from WordPress but some plugins disable or prevent CRON from working.
    My recommendation in this case is either you create this schedule through the Server Cron or you install a plugin to reaffirm your schedule

    Login or Signup to reply.
  3. One thing that comes to mind here is, why do you need to use the cron at all? If your next function is to be run immediately after another, just run that function at that time. No need to add to the cron. Cron is generally used for scheduling things that need to be run on a recurring schedule, not necessarily for running a function one time after another function has run.

    Also, check your WordPress timezone vs. your server timezone. That trips people up occasionally.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search