Automattic\WooCommerce\Internal\Admin\Schedulers

OrdersScheduler::is_test_orderpublic staticWC 10.7.0

Check if an order is a test order that should be excluded from analytics.

For refunds, the parent order is checked instead, since refunds do not carry the test mode metadata directly.

Method of the class: OrdersScheduler{}

Hooks from the method

Returns

true|false.

Usage

$result = OrdersScheduler::is_test_order( $order );
$order(WC_Abstract_Order) (required)
Order object.

Changelog

Since 10.7.0 Introduced.

OrdersScheduler::is_test_order() code WC 10.8.1

public static function is_test_order( $order ) {
	if ( ! $order instanceof \WC_Abstract_Order ) {
		return false;
	}

	// For refunds, check the parent order.
	$check_order = $order;
	if ( 'shop_order_refund' === $order->get_type() ) {
		$check_order = wc_get_order( $order->get_parent_id() );
		if ( ! $check_order instanceof \WC_Abstract_Order ) {
			return false;
		}
	}

	$is_test = 'test' === $check_order->get_meta( '_wcpay_mode' );

	/**
	 * Filter whether an order is a test order excluded from analytics.
	 *
	 * Use this filter to customize test order detection beyond the default
	 * WCPay test mode check, e.g., to exclude orders from other payment
	 * gateways' test/sandbox modes.
	 *
	 * @param bool               $is_test Whether the order is a test order.
	 * @param \WC_Abstract_Order $order   The order being checked (for refunds, this is the parent order).
	 *
	 * @since 10.7.0
	 */
	return apply_filters( 'woocommerce_analytics_is_test_order', $is_test, $check_order );
}