Automattic\WooCommerce\Internal\OrderReviews
Scheduler::handle_woocommerce_order_status_completed
Schedule the review-request email when an order becomes complete.
Method of the class: Scheduler{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$Scheduler = new Scheduler(); $Scheduler->handle_woocommerce_order_status_completed( $order_id ): void;
- $order_id(int) (required)
- The completed order ID.
Scheduler::handle_woocommerce_order_status_completed() Scheduler::handle woocommerce order status completed code WC 10.8.1
public function handle_woocommerce_order_status_completed( int $order_id ): void {
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return;
}
$email = $this->get_email();
if ( null === $email || ! $email->is_enabled() ) {
$this->log_skip( $order_id, 'email is disabled' );
return;
}
if ( $order->get_meta( self::SCHEDULED_META_KEY ) ) {
$this->log_skip( $order_id, 'already scheduled' );
return;
}
/**
* Filter whether to schedule the review-request email for a given order.
*
* Return false to opt a specific order out of the automated email while
* leaving the email enabled store-wide.
*
* @param bool $should_send Whether to schedule the email. Default true.
* @param WC_Order $order The order being processed.
*
* @since 10.8.0
*/
$should_send = (bool) apply_filters( 'woocommerce_should_send_review_request', true, $order );
if ( ! $should_send ) {
$this->log_skip( $order_id, 'opt-out filter returned false' );
return;
}
$when = time() + $email->get_delay_seconds();
as_schedule_single_action( $when, self::ACTION_HOOK, array( $order_id ) );
$order->update_meta_data( self::SCHEDULED_META_KEY, (string) $when );
$order->save();
}