confirm_order( $order ); } /** * Block checkout: an order has been placed. * * @param WC_Order $order The order object. * * @return void */ public function on_block_checkout( WC_Order $order ): void { $this->confirm_order( $order ); } /** * Send the shopper a confirmation for their own order. * * @param WC_Order $order The order that was just placed. * * @return void */ private function confirm_order( WC_Order $order ): void { if ( ! Settings::get( 'wcOrderNotificationEnabled', true ) ) { return; } if ( $order->get_meta( self::NOTIFIED_META ) ) { return; } $subscriber_token = SubscriberToken::for_current_visitor(); if ( '' === $subscriber_token ) { return; } // Record who this order belongs to before sending. Even if the send // fails, a later feature notifying about this order knows the shopper. $order->update_meta_data( self::TOKEN_META, $subscriber_token ); $order->save(); // Guests can't open the My Account order page, so link them to the // order-received page, which is authorized by the order key. $target_url = $order->get_customer_id() ? $order->get_view_order_url() : $order->get_checkout_order_received_url(); $payload = array( 'title' => __( 'Thanks for your order', 'notifypress' ), /* translators: %s: order number. */ 'message' => sprintf( __( 'Order %s is confirmed. Tap to track it.', 'notifypress' ), $order->get_order_number() ), 'target_url' => $target_url, ); if ( ! Notifier::notify_subscriber( $subscriber_token, $payload ) ) { return; } $order->update_meta_data( self::NOTIFIED_META, time() ); $order->save(); } }