Automattic\WooCommerce\Internal\ReceiptRendering
ReceiptRenderingEngine::get_existing_receipt
Get the file name of an existing receipt file for an order.
A receipt is considered to be available for the order if there's an order meta entry with key RECEIPT_FILE_NAME_META_KEY AND the transient file it points to exists AND it has not expired.
Method of the class: ReceiptRenderingEngine{}
No Hooks.
Returns
String|null. The receipt file name, or null if no receipt is currently available for the order.
Usage
$ReceiptRenderingEngine = new ReceiptRenderingEngine(); $ReceiptRenderingEngine->get_existing_receipt( $order ): ?string;
- $order(WC_Abstract_Order) (required)
- The order object or order id to get the receipt for.
ReceiptRenderingEngine::get_existing_receipt() ReceiptRenderingEngine::get existing receipt code WC 10.4.3
public function get_existing_receipt( $order ): ?string {
if ( ! $order instanceof WC_Abstract_Order ) {
$order = wc_get_order( $order );
if ( false === $order ) {
return null;
}
}
$existing_receipt_filename = $order->get_meta( self::RECEIPT_FILE_NAME_META_KEY, true );
if ( '' === $existing_receipt_filename ) {
return null;
}
$file_path = $this->transient_files_engine->get_transient_file_path( $existing_receipt_filename );
if ( is_null( $file_path ) ) {
return null;
}
return $this->transient_files_engine->file_has_expired( $file_path ) ? null : $existing_receipt_filename;
}