WC_Email_Customer_Abandoned_Cart_Recovery::is_order_eligible_for_recovery
Whether an order is in a state that warrants a recovery email.
The order must (a) be in one of the eligible statuses, (b) have lived in that state for at least ABANDONMENT_THRESHOLD_SECONDS (so we don't nudge customers who are actively still on the page), and (c) have a valid billing email — checkout-draft orders in particular can land in the eligible status without a recipient.
Single source of truth: called both by trigger() (defence-in-depth at send time) and by the manual-send dropdown gates. Partners can widen the eligible-status set via woocommerce_abandoned_cart_recovery_eligible_statuses both paths will agree.
Method of the class: WC_Email_Customer_Abandoned_Cart_Recovery{}
Hooks from the method
Returns
bool.
Usage
// protected - for code of main (parent) or child class $result = $this->is_order_eligible_for_recovery( $order ): bool;
- $order(WC_Order) (required)
- Order to evaluate.
Changelog
| Since 11.0.0 | Introduced. |
WC_Email_Customer_Abandoned_Cart_Recovery::is_order_eligible_for_recovery() WC Email Customer Abandoned Cart Recovery::is order eligible for recovery code WC 11.1.2
protected function is_order_eligible_for_recovery( WC_Order $order ): bool {
/**
* Filter the order statuses that are eligible to receive the abandoned cart recovery email.
*
* The filter is applied at two points in the order lifecycle, which pass different
* defaults because they cover different statuses:
*
* - At send time (here), the default is `pending` and `checkout-draft`, covering
* abandonment from both the classic and the block checkout, used in manual email trigger path
* from the order edit page.
* - When the automated send is scheduled, the default is `pending` only.
* Store API orders are generally created in `checkout-draft`, which is not supported
* yet for automatic scheduled email.
* {@see \Automattic\WooCommerce\Internal\AbandonedCartRecovery\Scheduler::get_eligible_statuses()}
*
* @since 11.0.0
*
* @param string[] $eligible_statuses Default: `pending` and `checkout-draft` at manual send time, `pending` when scheduling.
* @param WC_Order|null $order Order being inspected, or null if it could not be loaded.
*/
$eligible_statuses = (array) apply_filters(
'woocommerce_abandoned_cart_recovery_eligible_statuses',
self::ABANDONED_STATUSES,
$order
);
if ( ! in_array( $order->get_status(), $eligible_statuses, true ) ) {
return false;
}
$date_created = $order->get_date_created();
if ( ! $date_created ) {
return false;
}
if ( ( time() - $date_created->getTimestamp() ) < self::ABANDONMENT_THRESHOLD_SECONDS ) {
return false;
}
return is_email( $order->get_billing_email() ) !== false;
}