Automattic\WooCommerce\Internal\ReceiptRendering

ReceiptRenderingRestController::create_order_receipt()publicWC 1.0

Handle the POST /orders/id/receipt:

Return the data for a receipt if it exists, or create a new receipt and return its data otherwise.

Optional query string arguments:

expiration_date: formatted as yyyy-mm-dd. expiration_days: a number, 0 is today, 1 is tomorrow, etc. force_new: defaults to false, if true, create a new receipt even if one already exists for the order.

If neither expiration_date nor expiration_days are supplied, the default is expiration_days = 1.

Method of the class: ReceiptRenderingRestController{}

No Hooks.

Return

Array|WP_Error. Request response or an error.

Usage

$ReceiptRenderingRestController = new ReceiptRenderingRestController();
$ReceiptRenderingRestController->create_order_receipt( $request );
$request(WP_REST_Request) (required)
The received request.

ReceiptRenderingRestController::create_order_receipt() code WC 9.6.1

public function create_order_receipt( WP_REST_Request $request ) {
	$expiration_date =
		$request->get_param( 'expiration_date' ) ??
		gmdate( 'Y-m-d', strtotime( "+{$request->get_param('expiration_days')} days" ) );

	$order_id = $request->get_param( 'id' );

	$filename = wc_get_container()->get( ReceiptRenderingEngine::class )->generate_receipt( $order_id, $expiration_date, $request->get_param( 'force_new' ) );

	return is_null( $filename ) ?
		new WP_Error( 'woocommerce_rest_not_found', __( 'Order not found', 'woocommerce' ), array( 'status' => 404 ) ) :
		$this->get_response_for_file( $filename );
}