WC_Shortcode_Checkout::order_received()private staticWC 1.0

Show the thanks page.

Метод класса: WC_Shortcode_Checkout{}

Возвращает

null. Ничего (null).

Использование

$result = WC_Shortcode_Checkout::order_received( $order_id );
$order_id(int)
Order ID.

Код WC_Shortcode_Checkout::order_received() WC 8.9.0

private static function order_received( $order_id = 0 ) {
	$order = false;

	// Get the order.
	$order_id  = apply_filters( 'woocommerce_thankyou_order_id', absint( $order_id ) );
	$order_key = apply_filters( 'woocommerce_thankyou_order_key', empty( $_GET['key'] ) ? '' : wc_clean( wp_unslash( $_GET['key'] ) ) ); // WPCS: input var ok, CSRF ok.

	if ( $order_id > 0 ) {
		$order = wc_get_order( $order_id );

		if ( ( ! $order instanceof WC_Order ) || ! hash_equals( $order->get_order_key(), $order_key ) ) {
			$order = false;
		}
	}

	// Empty awaiting payment session.
	unset( WC()->session->order_awaiting_payment );

	// In case order is created from admin, but paid by the actual customer, store the ip address of the payer
	// when they visit the payment confirmation page.
	if ( $order && $order->is_created_via( 'admin' ) ) {
		$order->set_customer_ip_address( WC_Geolocation::get_ip_address() );
		$order->save();
	}

	// Empty current cart.
	wc_empty_cart();

	// If the specified order ID was invalid, we still render the default order received page (which will simply
	// state that the order was received, but will not output any other details: this makes it harder to probe for
	// valid order IDs than if we state that the order ID was not recognized).
	if ( ! $order ) {
		wc_get_template( 'checkout/thankyou.php', array( 'order' => false ) );
		return;
	}

	/**
	 * Indicates if known (non-guest) shoppers need to be logged in before we let
	 * them access the order received page.
	 *
	 * @param bool $verify_known_shoppers If verification is required.
	 *
	 * @since 8.4.0
	 */
	$verify_known_shoppers = apply_filters( 'woocommerce_order_received_verify_known_shoppers', true );
	$order_customer_id     = $order->get_customer_id();

	// For non-guest orders, require the user to be logged in before showing this page.
	if ( $verify_known_shoppers && $order_customer_id && get_current_user_id() !== $order_customer_id ) {
		wc_get_template( 'checkout/order-received.php', array( 'order' => false ) );
		wc_print_notice( esc_html__( 'Please log in to your account to view this order.', 'woocommerce' ), 'notice' );
		woocommerce_login_form( array( 'redirect' => $order->get_checkout_order_received_url() ) );
		return;
	}

	// For guest orders, request they verify their email address (unless we can identify them via the active user session).
	if ( self::guest_should_verify_email( $order, 'order-received' ) ) {
		wc_get_template( 'checkout/order-received.php', array( 'order' => false ) );
		wc_get_template(
			'checkout/form-verify-email.php',
			array(
				'failed_submission' => ! empty( $_POST['email'] ), // phpcs:ignore WordPress.Security.NonceVerification.Missing
				'verify_url'        => $order->get_checkout_order_received_url(),
			)
		);
		return;
	}

	// Otherwise, display the thank you (order received) page.
	wc_get_template( 'checkout/thankyou.php', array( 'order' => $order ) );
}