Automattic\WooCommerce\Admin\API\Reports

Controller::get_order_number()protectedWC 1.0

Get the order number for an order. If no filter is present for woocommerce_order_number, we can just return the ID. Returns the parent order number if the order is actually a refund.

Method of the class: Controller{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_order_number( $order_id );
$order_id(int) (required)
Order ID.

Controller::get_order_number() code WC 7.3.0

protected function get_order_number( $order_id ) {
	$order = wc_get_order( $order_id );

	if ( ! $order instanceof \WC_Order && ! $order instanceof \WC_Order_Refund ) {
		return null;
	}

	if ( 'shop_order_refund' === $order->get_type() ) {
		$order = wc_get_order( $order->get_parent_id() );
	}

	if ( ! has_filter( 'woocommerce_order_number' ) ) {
		return $order->get_id();
	}

	return $order->get_order_number();
}