WC_Email_Customer_Abandoned_Cart_Recovery::register_order_actionpublicWC 11.0.0

Add the manual-send item to the order actions dropdown.

Surfaced for the statuses listed in ABANDONED_STATUSES (pending + checkout-draft) so merchants can't accidentally email a "pick up where you left off" prompt to a customer whose order has already moved past abandonment. A capability check guards against role configurations that grant the order edit page to users without edit_shop_orders.

Method of the class: WC_Email_Customer_Abandoned_Cart_Recovery{}

No Hooks.

Returns

Array.

Usage

$WC_Email_Customer_Abandoned_Cart_Recovery = new WC_Email_Customer_Abandoned_Cart_Recovery();
$WC_Email_Customer_Abandoned_Cart_Recovery->register_order_action( $actions, $order ): array;
$actions(array) (required)
Existing order actions keyed by action id.
$order(WC_Order|null) (required)
Order being rendered, or null in contexts without one.

Changelog

Since 11.0.0 Introduced.

WC_Email_Customer_Abandoned_Cart_Recovery::register_order_action() code WC 11.0.0

public function register_order_action( $actions, $order ): array {
	if ( ! $order instanceof WC_Order ) {
		return $actions;
	}

	if ( ! current_user_can( 'edit_shop_orders' ) ) {
		return $actions;
	}

	// Mirror trigger()'s preconditions: don't surface an action that would
	// silently no-op when the merchant clicks it.
	if ( ! $this->is_enabled() || self::is_suppressed() ) {
		return $actions;
	}

	if ( ! $this->is_order_eligible_for_recovery( $order ) ) {
		return $actions;
	}

	// Customer-side preference wins over merchant action — don't surface
	// "Send" if the recipient has already opted out.
	if ( self::is_recipient_unsubscribed( $order->get_billing_email() ) ) {
		return $actions;
	}

	// trigger() refuses to dispatch a second time once META_KEY_SENT_AT is
	// set, so don't surface a control that would silently no-op.
	if ( '' !== (string) $order->get_meta( self::META_KEY_SENT_AT ) ) {
		return $actions;
	}

	$actions[ self::MANUAL_RECOVERY_EMAIL_SEND_ACTION ] = __( 'Send abandoned cart recovery email', 'woocommerce' );

	return $actions;
}