# Payment Reminder for Unpaid Orders

> Re-sends the order details with a payment link to customers whose order is still pending payment a few hours after checkout, recovering failed or abandoned payments.

- Type: PHP
- Runs: Run everywhere
- Category: [WooCommerce](https://wpide.com/library/category/woocommerce/)
- Requires: WooCommerce
- Tags: woocommerce, orders, email, payments
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/woo-unpaid-order-reminder/

## Code

```php
$wpide_reminder_hours = 6; // Hours after checkout.

add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'wpide_unpaid_order_reminders' ) ) {
        wp_schedule_event( time() + 600, 'hourly', 'wpide_unpaid_order_reminders' );
    }
} );

add_action( 'wpide_unpaid_order_reminders', function () use ( $wpide_reminder_hours ) {
    if ( ! function_exists( 'wc_get_orders' ) ) {
        return;
    }

    $orders = wc_get_orders( array(
        'status'       => 'pending',
        'date_created' => ( time() - 3 * DAY_IN_SECONDS ) . '...' . ( time() - $wpide_reminder_hours * HOUR_IN_SECONDS ),
        'limit'        => 20,
        'meta_query'   => array( array( 'key' => '_wpide_payment_reminder', 'compare' => 'NOT EXISTS' ) ), // phpcs:ignore WordPress.DB.SlowDBQuery
    ) );

    $emails = WC()->mailer()->get_emails();

    foreach ( $orders as $order ) {
        if ( ! $order->get_billing_email() || ! $order->needs_payment() ) {
            continue;
        }

        $order->update_meta_data( '_wpide_payment_reminder', time() );
        $order->save_meta_data();

        if ( isset( $emails['WC_Email_Customer_Invoice'] ) ) {
            $emails['WC_Email_Customer_Invoice']->trigger( $order->get_id(), $order );
            $order->add_order_note( 'Payment reminder sent to the customer.' );
        }
    }
} );
```

## Notes

Uses WooCommerce's "Order details" email, sends one reminder per order and handles 20 orders per hourly WP-Cron run.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Payment Reminder for Unpaid Orders" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
