WC_Email_Customer_Abandoned_Cart_Recovery::trigger
Trigger the sending of this email.
Called by Scheduler::handle_scheduled_send() after Action Scheduler dispatches woocommerce_send_abandoned_cart_recovery_notification, and directly by the manual-send action on the order edit page.
Method of the class: WC_Email_Customer_Abandoned_Cart_Recovery{}
No Hooks.
Returns
true|false. True when an email was dispatched in this call, false when any gate (suppression, disabled, ineligible, unsubscribed, dedup) or the underlying send() rejected the request.
Usage
$WC_Email_Customer_Abandoned_Cart_Recovery = new WC_Email_Customer_Abandoned_Cart_Recovery(); $WC_Email_Customer_Abandoned_Cart_Recovery->trigger( $order_id ): bool;
- $order_id(int) (required)
- The order ID.
Changelog
| Since 11.0.0 | Introduced. |
WC_Email_Customer_Abandoned_Cart_Recovery::trigger() WC Email Customer Abandoned Cart Recovery::trigger code WC 11.0.0
public function trigger( $order_id ): bool {
if ( self::is_suppressed() ) {
return false;
}
$this->setup_locale();
// Reset state from any previous invocation so a call with an invalid order id
// cannot re-use the previous recipient / placeholders.
$this->object = false;
$this->recipient = '';
$this->placeholders['{order_date}'] = '';
$this->placeholders['{order_number}'] = '';
$order = $order_id ? wc_get_order( $order_id ) : false;
if ( $order instanceof WC_Order ) {
$this->object = $order;
$this->recipient = $order->get_billing_email();
$date_created = $order->get_date_created();
$this->placeholders['{order_date}'] = $date_created ? wc_format_datetime( $date_created ) : '';
$this->placeholders['{order_number}'] = $order->get_order_number();
}
$dispatched = false;
if (
$this->is_enabled()
&& $this->get_recipient()
&& $this->object instanceof WC_Order
&& $this->is_order_eligible_for_recovery( $this->object )
&& ! self::is_recipient_unsubscribed( $this->get_recipient() )
&& '' === (string) $this->object->get_meta( self::META_KEY_SENT_AT )
) {
$dispatched = (bool) $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
// Only record the send timestamp when the dispatch actually succeeded.
// Subsequent invocations (duplicate AS firings, post-manual auto fires)
// short-circuit on this meta before reaching `send()` again.
if ( $dispatched ) {
$this->object->update_meta_data( self::META_KEY_SENT_AT, (string) time() );
$this->object->save_meta_data();
}
}
$this->restore_locale();
return $dispatched;
}