WP-Cron and pending or cancelled orders

  1. Home
  2. /
  3. Krokedil general support info
  4. /
  5. WP-Cron and pending or cancelled orders

WP-Cron and pending or cancelled orders

If you have made sure callbacks are not blocked by your site and still are experiencing pending or cancelled orders in WooCommerce for successful payments, the issue might be due to WP-Cron not working. WP-Cron is WordPress’s way of handling scheduled tasks.


Scheduled actions and WP-Cron not working


When scheduled actions and WP-Cron are not working several critical issues can arise, primarily impacting order management and synchronization between your WooCommerce store and the payment service provider (PSP).

Here are a few examples of what can happen with orders when you are having issues with WP-Cron on your site:

1. Stuck Orders in “Pending Payment” Status

WooCommerce’s Default Behavior when a customer initiates a payment is that a WooCommerce order is typically created first with the status “Pending Payment.” The customer is then redirected to the payment gateway to finalize the payment. If WP-Cron isn’t running, WooCommerce’s internal woocommerce_cancel_unpaid_orders scheduled action (which relies on WP-Cron) won’t execute. This can cause:

  • Abandoned orders remain pending
    If a customer abandons the payment process, or if the payment fails (example  insufficient funds or card declined), the corresponding WooCommerce order will remain in “Pending Payment” status indefinitely.
  • Held Stock not released
    WooCommerce by default, places products in a “held” state for a set period (configured in WooCommerce > Settings > Products > Inventory) while a payment is pending. If WP-Cron fails, these held stock items for abandoned or failed orders will not be released, leading to inaccurate inventory and potentially preventing other customers from purchasing those items.
  • No automatic order status updates
    The payment provider usually communicates the final payment status back to WooCommerce. However, crucial backend processes for updating the WooCommerce order status (from “Pending Payment” to “Processing” or “Failed”) might be triggered by scheduled actions. If these don’t run, orders can get stuck in an incorrect state.

2. Synchronization Issues with Order Management

Most of our plugins have support for order management which allows merchants to perform actions like capturing, refunding, and canceling orders directly from the WooCommerce admin. While many of these actions might be triggered immediately by user interaction, some background synchronization tasks that keep the WooCommerce order status in sync with the payment service provider (PSP) system might rely on scheduled actions. If WP-Cron is down it can cause:

  • Delayed captures
    Automatic captures of orders, for example when the WooCommerce order status is set to “Completed”, might not happen promptly, delaying the payment processing.
  • Out-of-sync statuses
    The order status in WooCommerce might not accurately reflect the true status or data on the order from the payment service provider (PSP), leading to confusion for merchants and potential discrepancies in reporting.
  • Failed refunds/cancellations:
    While manual refunds/cancellations initiated from WooCommerce should ideally trigger direct API calls to the payment provider, there could be retry mechanisms or secondary processes that depend on scheduled actions. If these fail, a refund/cancellation initiated in WooCommerce might not be fully processed or reflected in the payment service provider (PSP).

3. Missed or Delayed Notifications

WooCommerce sends various automated emails to the customer related to order status changes (example order processing, payment failed, order canceled). Many of these are dispatched via WP-Cron. If WP-Cron isn’t working, customers might not receive order confirmations, payment failure notifications, or cancellation emails, leading to a poor customer experience and increased support inquiries.

Merchants might also miss important notifications about order issues or updates.

4. Performance Issues (in some cases)

While WP-Cron is not running means fewer tasks are being processed, a stuck WP-Cron (example due to a problematic scheduled action that never completes) can actually consume server resources, leading to overall site slowdowns. If WP-Cron is disabled but no server-side cron is set up, a large backlog of scheduled tasks can build up. When a user finally visits the site, the system tries to process all these overdue tasks at once, which can lead to severe performance degradation or even timeouts.


General steps on how to diagnose and fix WP-Cron issues


When having issues with WP-Cron the merchant needs to debug what might be causing this, here are a few steps to follow:

  1. Install WP Crontrol, essential for seeing all scheduled events.
    https://wordpress.org/plugins/wp-crontrol/
  2. Check for overdue/missed Hooks:
    – woocommerce_cancel_unpaid_orders
    – action_scheduler_run_queue, this is the core hook for Action Scheduler, which many plugins, including payment gateways, use.
  3. Verify wp-config.php for DISABLE_WP_CRON, if set to true, ensure a proper server-side cron job is configured.
  4. Check Server Logs. Look for errors related to wp-cron.php or any PHP errors that might be terminating processes prematurely.
  5. Temporarily Disable Caching. Aggressive caching can prevent wp-cron.php from executing.
  6. Isolate Plugin Conflicts. Deactivate other plugins to see if one is interfering with WP-Cron or the payment gateway’s scheduled tasks. Note that WooCommerce is required for our plugins to work.

You can read WooCommerce documentation on Scheduled actions and WP-Cron here:
https://woocommerce.com/document/understanding-the-woocommerce-system-status-report/scheduled-actions/

WooCommerce also have a complete guide on how to debug WP-Cron here:
https://woocommerce.com/document/subscriptions/develop/complete-guide-to-scheduled-events-with-subscriptions/#debugging-wp-cron