Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Internal/ReceiptR...
File: ReceiptRenderingEngine.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Automattic\WooCommerce\Internal\ReceiptRendering;
[2] Fix | Delete
[3] Fix | Delete
use Automattic\WooCommerce\Internal\Orders\PaymentInfo;
[4] Fix | Delete
use Automattic\WooCommerce\Internal\TransientFiles\TransientFilesEngine;
[5] Fix | Delete
use Automattic\WooCommerce\Proxies\LegacyProxy;
[6] Fix | Delete
use Automattic\WooCommerce\Utilities\ArrayUtil;
[7] Fix | Delete
use Exception;
[8] Fix | Delete
use WC_Abstract_Order;
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* This class generates printable order receipts as transient files (see src/Internal/TransientFiles).
[12] Fix | Delete
* The template for the receipt is Templates/order-receipt.php, it uses the variables returned as array keys
[13] Fix | Delete
* 'get_order_data'.
[14] Fix | Delete
*
[15] Fix | Delete
* When a receipt is generated for an order with 'generate_receipt' the receipt file name is stored as order meta
[16] Fix | Delete
* (see RECEIPT_FILE_NAME_META_KEY) for later retrieval with 'get_existing_receipt'. Beware! The files pointed
[17] Fix | Delete
* by such meta keys could have expired and thus no longer exist. 'get_existing_receipt' will appropriately return null
[18] Fix | Delete
* if the meta entry exists but the file doesn't.
[19] Fix | Delete
*/
[20] Fix | Delete
class ReceiptRenderingEngine {
[21] Fix | Delete
[22] Fix | Delete
private const FONT_SIZE = 12;
[23] Fix | Delete
[24] Fix | Delete
private const LINE_HEIGHT = self::FONT_SIZE * 1.5;
[25] Fix | Delete
[26] Fix | Delete
private const ICON_HEIGHT = self::LINE_HEIGHT;
[27] Fix | Delete
[28] Fix | Delete
private const ICON_WIDTH = self::ICON_HEIGHT * ( 4 / 3 );
[29] Fix | Delete
[30] Fix | Delete
private const MARGIN = 16;
[31] Fix | Delete
[32] Fix | Delete
private const TITLE_FONT_SIZE = 24;
[33] Fix | Delete
[34] Fix | Delete
private const FOOTER_FONT_SIZE = 10;
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* This array must contain all the names of the files in the CardIcons directory (without extension),
[38] Fix | Delete
* except 'unknown'.
[39] Fix | Delete
*/
[40] Fix | Delete
private const KNOWN_CARD_TYPES = array( 'amex', 'diners', 'discover', 'interac', 'jcb', 'mastercard', 'visa' );
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Order meta key that stores the file name of the last generated receipt.
[44] Fix | Delete
*/
[45] Fix | Delete
public const RECEIPT_FILE_NAME_META_KEY = '_receipt_file_name';
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* The instance of TransientFilesEngine to use.
[49] Fix | Delete
*
[50] Fix | Delete
* @var TransientFilesEngine
[51] Fix | Delete
*/
[52] Fix | Delete
private $transient_files_engine;
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* The instance of LegacyProxy to use.
[56] Fix | Delete
*
[57] Fix | Delete
* @var LegacyProxy
[58] Fix | Delete
*/
[59] Fix | Delete
private $legacy_proxy;
[60] Fix | Delete
[61] Fix | Delete
/**
[62] Fix | Delete
* Initializes the class.
[63] Fix | Delete
*
[64] Fix | Delete
* @param TransientFilesEngine $transient_files_engine The instance of TransientFilesEngine to use.
[65] Fix | Delete
* @param LegacyProxy $legacy_proxy The instance of LegacyProxy to use.
[66] Fix | Delete
* @internal
[67] Fix | Delete
*/
[68] Fix | Delete
final public function init( TransientFilesEngine $transient_files_engine, LegacyProxy $legacy_proxy ) {
[69] Fix | Delete
$this->transient_files_engine = $transient_files_engine;
[70] Fix | Delete
$this->legacy_proxy = $legacy_proxy;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Get the (transient) file name of the receipt for an order, creating a new file if necessary.
[75] Fix | Delete
*
[76] Fix | Delete
* If $force_new is false, and a receipt file for the order already exists (as pointed by order meta key
[77] Fix | Delete
* RECEIPT_FILE_NAME_META_KEY), then the name of the already existing receipt file is returned.
[78] Fix | Delete
*
[79] Fix | Delete
* If $force_new is true, OR if it's false but no receipt file for the order exists (no order meta with key
[80] Fix | Delete
* RECEIPT_FILE_NAME_META_KEY exists, OR it exists but the file it points to doesn't), then a new receipt
[81] Fix | Delete
* transient file is created with the supplied expiration date (defaulting to "tomorrow"), and the new file name
[82] Fix | Delete
* is stored as order meta with the key RECEIPT_FILE_NAME_META_KEY.
[83] Fix | Delete
*
[84] Fix | Delete
* @param int|WC_Abstract_Order $order The order object or order id to get the receipt for.
[85] Fix | Delete
* @param string|int|null $expiration_date GMT expiration date formatted as yyyy-mm-dd, or as a timestamp, or null for "tomorrow".
[86] Fix | Delete
* @param bool $force_new If true, creates a new receipt file even if one already exists for the order.
[87] Fix | Delete
* @return string|null The file name of the new or already existing receipt file, null if an order id is passed and the order doesn't exist.
[88] Fix | Delete
* @throws InvalidArgumentException Invalid expiration date (wrongly formatted, or it's a date in the past).
[89] Fix | Delete
* @throws Exception The directory to store the file doesn't exist and can't be created.
[90] Fix | Delete
*/
[91] Fix | Delete
public function generate_receipt( $order, $expiration_date = null, bool $force_new = false ): ?string {
[92] Fix | Delete
if ( ! $order instanceof WC_Abstract_Order ) {
[93] Fix | Delete
$order = wc_get_order( $order );
[94] Fix | Delete
if ( false === $order ) {
[95] Fix | Delete
return null;
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( ! $force_new ) {
[100] Fix | Delete
$existing_receipt_filename = $this->get_existing_receipt( $order );
[101] Fix | Delete
if ( ! is_null( $existing_receipt_filename ) ) {
[102] Fix | Delete
return $existing_receipt_filename;
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
$expiration_date ??=
[107] Fix | Delete
$this->legacy_proxy->call_function(
[108] Fix | Delete
'gmdate',
[109] Fix | Delete
'Y-m-d',
[110] Fix | Delete
$this->legacy_proxy->call_function(
[111] Fix | Delete
'strtotime',
[112] Fix | Delete
'+1 days'
[113] Fix | Delete
)
[114] Fix | Delete
);
[115] Fix | Delete
[116] Fix | Delete
/**
[117] Fix | Delete
* Filter to customize the set of data that is used to render the receipt.
[118] Fix | Delete
* The formatted line items aren't included, use the woocommerce_printable_order_receipt_formatted_line_item
[119] Fix | Delete
* filter to customize those.
[120] Fix | Delete
*
[121] Fix | Delete
* See the value returned by the 'get_order_data' and 'get_woo_pay_data' methods for a reference of
[122] Fix | Delete
* the structure of the data.
[123] Fix | Delete
*
[124] Fix | Delete
* See the template file, Templates/order-receipt.php, for reference on how the data is used.
[125] Fix | Delete
*
[126] Fix | Delete
* @param array $data The original set of data.
[127] Fix | Delete
* @param WC_Abstract_Order $order The order for which the receipt is being generated.
[128] Fix | Delete
* @returns array The updated set of data.
[129] Fix | Delete
*
[130] Fix | Delete
* @since 9.0.0
[131] Fix | Delete
*/
[132] Fix | Delete
$data = apply_filters( 'woocommerce_printable_order_receipt_data', $this->get_order_data( $order ), $order );
[133] Fix | Delete
[134] Fix | Delete
$formatted_line_items = array();
[135] Fix | Delete
$row_index = 0;
[136] Fix | Delete
foreach ( $data['line_items'] as $line_item_data ) {
[137] Fix | Delete
$quantity_data = isset( $line_item_data['quantity'] ) ? " × {$line_item_data['quantity']}" : '';
[138] Fix | Delete
$line_item_display_data = array(
[139] Fix | Delete
'inner_html' => "<td>{$line_item_data['title']}$quantity_data</td><td>{$line_item_data['amount']}</td>",
[140] Fix | Delete
'tr_attributes' => array(),
[141] Fix | Delete
'row_index' => $row_index++,
[142] Fix | Delete
);
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Filter to customize the HTML that gets rendered for each order line item in the receipt.
[146] Fix | Delete
*
[147] Fix | Delete
* $line_item_display_data will be passed (and must be returned) with the following keys:
[148] Fix | Delete
*
[149] Fix | Delete
* - inner_html: the HTML text that will go inside a <tr> element, note that
[150] Fix | Delete
* wp_kses_post will be applied to this text before actual rendering.
[151] Fix | Delete
* - tr_attributes: attributes (e.g. 'class', 'data', 'style') that will be applied to the <tr> element,
[152] Fix | Delete
* as an associative array of attribute name => value.
[153] Fix | Delete
* - row_index: a number that starts at 0 and increases by one for each processed line item.
[154] Fix | Delete
*
[155] Fix | Delete
* $line_item_data will contain the following keys:
[156] Fix | Delete
*
[157] Fix | Delete
* - type: One of 'product', 'subtotal', 'discount', 'fee', 'shipping_total', 'taxes_total', 'amount_paid'
[158] Fix | Delete
* - title
[159] Fix | Delete
* - amount (formatted with wc_price)
[160] Fix | Delete
* - item (only when type is 'product'), and instance of WC_Order_Item
[161] Fix | Delete
* - quantity (only when type is 'product')
[162] Fix | Delete
*
[163] Fix | Delete
* @param string $line_item_display_data Data to use to generate the HTML table row to be rendered for the line item.
[164] Fix | Delete
* @param array $line_item_data The relevant data for the line item for which the HTML table row is being generated.
[165] Fix | Delete
* @param WC_Abstract_Order $order The order for which the receipt is being generated.
[166] Fix | Delete
* @return string The actual data to use to generate the HTML for the line item.
[167] Fix | Delete
*
[168] Fix | Delete
* @since 9.0.0
[169] Fix | Delete
*/
[170] Fix | Delete
$line_item_display_data = apply_filters( 'woocommerce_printable_order_receipt_line_item_display_data', $line_item_display_data, $line_item_data, $order );
[171] Fix | Delete
$attributes = '';
[172] Fix | Delete
foreach ( $line_item_display_data['tr_attributes'] as $attribute_name => $attribute_value ) {
[173] Fix | Delete
$attribute_value = esc_attr( $attribute_value );
[174] Fix | Delete
$attributes .= " $attribute_name=\"$attribute_value\"";
[175] Fix | Delete
}
[176] Fix | Delete
$formatted_line_items[] = wp_kses_post( "<tr$attributes>{$line_item_display_data['inner_html']}</tr>" );
[177] Fix | Delete
}
[178] Fix | Delete
$data['formatted_line_items'] = $formatted_line_items;
[179] Fix | Delete
[180] Fix | Delete
ob_start();
[181] Fix | Delete
$css = include __DIR__ . '/Templates/order-receipt-css.php';
[182] Fix | Delete
$css = ob_get_contents();
[183] Fix | Delete
ob_end_clean();
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Filter to customize the CSS styles used to render the receipt.
[187] Fix | Delete
*
[188] Fix | Delete
* See Templates/order-receipt.php for guidance on the existing HTMl elements and their ids.
[189] Fix | Delete
* See Templates/order-receipt-css.php for the original CSS styles.
[190] Fix | Delete
*
[191] Fix | Delete
* @param string $css The original CSS styles to use.
[192] Fix | Delete
* @param WC_Abstract_Order $order The order for which the receipt is being generated.
[193] Fix | Delete
* @return string The actual CSS styles that will be used.
[194] Fix | Delete
*
[195] Fix | Delete
* @since 9.0.0
[196] Fix | Delete
*/
[197] Fix | Delete
$data['css'] = apply_filters( 'woocommerce_printable_order_receipt_css', $css, $order );
[198] Fix | Delete
[199] Fix | Delete
$default_template_path = __DIR__ . '/Templates/order-receipt.php';
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Filter the order receipt template path.
[203] Fix | Delete
*
[204] Fix | Delete
* @since 9.2.0
[205] Fix | Delete
* @hook wc_get_template
[206] Fix | Delete
* @param string $template The template path.
[207] Fix | Delete
* @param string $template_name The template name.
[208] Fix | Delete
* @param array $args The available data for the template.
[209] Fix | Delete
* @param string $template_path The template path.
[210] Fix | Delete
* @param string $default_path The default template path.
[211] Fix | Delete
*/
[212] Fix | Delete
$template_path = apply_filters(
[213] Fix | Delete
'wc_get_template',
[214] Fix | Delete
$default_template_path,
[215] Fix | Delete
'ReceiptRendering/order-receipt.php',
[216] Fix | Delete
$data,
[217] Fix | Delete
$default_template_path,
[218] Fix | Delete
$default_template_path
[219] Fix | Delete
);
[220] Fix | Delete
[221] Fix | Delete
if ( ! file_exists( $template_path ) ) {
[222] Fix | Delete
$template_path = $default_template_path;
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
ob_start();
[226] Fix | Delete
include $template_path;
[227] Fix | Delete
$rendered_template = ob_get_contents();
[228] Fix | Delete
ob_end_clean();
[229] Fix | Delete
[230] Fix | Delete
$file_name = $this->transient_files_engine->create_transient_file( $rendered_template, $expiration_date );
[231] Fix | Delete
[232] Fix | Delete
$order->update_meta_data( self::RECEIPT_FILE_NAME_META_KEY, $file_name );
[233] Fix | Delete
$order->save_meta_data();
[234] Fix | Delete
[235] Fix | Delete
return $file_name;
[236] Fix | Delete
}
[237] Fix | Delete
[238] Fix | Delete
/**
[239] Fix | Delete
* Get the file name of an existing receipt file for an order.
[240] Fix | Delete
*
[241] Fix | Delete
* A receipt is considered to be available for the order if there's an order meta entry with key
[242] Fix | Delete
* RECEIPT_FILE_NAME_META_KEY AND the transient file it points to exists AND it has not expired.
[243] Fix | Delete
*
[244] Fix | Delete
* @param WC_Abstract_Order $order The order object or order id to get the receipt for.
[245] Fix | Delete
* @return string|null The receipt file name, or null if no receipt is currently available for the order.
[246] Fix | Delete
* @throws Exception Thrown if a wrong file path is passed.
[247] Fix | Delete
*/
[248] Fix | Delete
public function get_existing_receipt( $order ): ?string {
[249] Fix | Delete
if ( ! $order instanceof WC_Abstract_Order ) {
[250] Fix | Delete
$order = wc_get_order( $order );
[251] Fix | Delete
if ( false === $order ) {
[252] Fix | Delete
return null;
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
$existing_receipt_filename = $order->get_meta( self::RECEIPT_FILE_NAME_META_KEY, true );
[257] Fix | Delete
[258] Fix | Delete
if ( '' === $existing_receipt_filename ) {
[259] Fix | Delete
return null;
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
$file_path = $this->transient_files_engine->get_transient_file_path( $existing_receipt_filename );
[263] Fix | Delete
if ( is_null( $file_path ) ) {
[264] Fix | Delete
return null;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
return $this->transient_files_engine->file_has_expired( $file_path ) ? null : $existing_receipt_filename;
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
/**
[271] Fix | Delete
* Get the order data that the receipt template will use.
[272] Fix | Delete
*
[273] Fix | Delete
* @param WC_Abstract_Order $order The order to get the data from.
[274] Fix | Delete
* @return array The order data as an associative array.
[275] Fix | Delete
*/
[276] Fix | Delete
private function get_order_data( WC_Abstract_Order $order ): array {
[277] Fix | Delete
$store_name = get_bloginfo( 'name' );
[278] Fix | Delete
if ( $store_name ) {
[279] Fix | Delete
/* translators: %s = store name */
[280] Fix | Delete
$receipt_title = sprintf( __( 'Receipt from %s', 'woocommerce' ), $store_name );
[281] Fix | Delete
} else {
[282] Fix | Delete
$receipt_title = __( 'Receipt', 'woocommerce' );
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
$order_id = $order->get_id();
[286] Fix | Delete
if ( $order_id ) {
[287] Fix | Delete
/* translators: %d = order id */
[288] Fix | Delete
$summary_title = sprintf( __( 'Summary: Order #%d', 'woocommerce' ), $order->get_id() );
[289] Fix | Delete
} else {
[290] Fix | Delete
$summary_title = __( 'Summary', 'woocommerce' );
[291] Fix | Delete
}
[292] Fix | Delete
[293] Fix | Delete
$get_price_args = array( 'currency' => $order->get_currency() );
[294] Fix | Delete
[295] Fix | Delete
$line_items_info = array();
[296] Fix | Delete
$line_items = $order->get_items( 'line_item' );
[297] Fix | Delete
foreach ( $line_items as $line_item ) {
[298] Fix | Delete
$line_item_product = $line_item->get_product();
[299] Fix | Delete
if ( false === $line_item_product ) {
[300] Fix | Delete
$line_item_title = $line_item->get_name();
[301] Fix | Delete
} else {
[302] Fix | Delete
$line_item_title =
[303] Fix | Delete
( $line_item_product instanceof \WC_Product_Variation ) ?
[304] Fix | Delete
( wc_get_product( $line_item_product->get_parent_id() )->get_name() ) . '. ' . $line_item_product->get_attribute_summary() :
[305] Fix | Delete
$line_item_product->get_name();
[306] Fix | Delete
}
[307] Fix | Delete
$line_items_info[] = array(
[308] Fix | Delete
'type' => 'product',
[309] Fix | Delete
'item' => $line_item,
[310] Fix | Delete
'title' => wp_kses( $line_item_title, array() ),
[311] Fix | Delete
'quantity' => $line_item->get_quantity(),
[312] Fix | Delete
'amount' => wc_price( $line_item->get_subtotal(), $get_price_args ),
[313] Fix | Delete
);
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
$line_items_info[] = array(
[317] Fix | Delete
'type' => 'subtotal',
[318] Fix | Delete
'title' => __( 'Subtotal', 'woocommerce' ),
[319] Fix | Delete
'amount' => wc_price( $order->get_subtotal(), $get_price_args ),
[320] Fix | Delete
);
[321] Fix | Delete
[322] Fix | Delete
$coupon_names = ArrayUtil::select( $order->get_coupons(), 'get_name', ArrayUtil::SELECT_BY_OBJECT_METHOD );
[323] Fix | Delete
if ( ! empty( $coupon_names ) ) {
[324] Fix | Delete
$line_items_info[] = array(
[325] Fix | Delete
'type' => 'discount',
[326] Fix | Delete
/* translators: %s = comma-separated list of coupon codes */
[327] Fix | Delete
'title' => sprintf( __( 'Discount (%s)', 'woocommerce' ), join( ', ', $coupon_names ) ),
[328] Fix | Delete
'amount' => wc_price( -$order->get_total_discount(), $get_price_args ),
[329] Fix | Delete
);
[330] Fix | Delete
}
[331] Fix | Delete
[332] Fix | Delete
foreach ( $order->get_fees() as $fee ) {
[333] Fix | Delete
$name = $fee->get_name();
[334] Fix | Delete
$line_items_info[] = array(
[335] Fix | Delete
'type' => 'fee',
[336] Fix | Delete
'title' => '' === $name ? __( 'Fee', 'woocommerce' ) : $name,
[337] Fix | Delete
'amount' => wc_price( $fee->get_total(), $get_price_args ),
[338] Fix | Delete
);
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
$shipping_total = (float) $order->get_shipping_total();
[342] Fix | Delete
if ( $shipping_total ) {
[343] Fix | Delete
$line_items_info[] = array(
[344] Fix | Delete
'type' => 'shipping_total',
[345] Fix | Delete
'title' => __( 'Shipping', 'woocommerce' ),
[346] Fix | Delete
'amount' => wc_price( $order->get_shipping_total(), $get_price_args ),
[347] Fix | Delete
);
[348] Fix | Delete
}
[349] Fix | Delete
[350] Fix | Delete
$total_taxes = 0;
[351] Fix | Delete
foreach ( $order->get_taxes() as $tax ) {
[352] Fix | Delete
$total_taxes += (float) $tax->get_tax_total() + (float) $tax->get_shipping_tax_total();
[353] Fix | Delete
}
[354] Fix | Delete
[355] Fix | Delete
if ( $total_taxes ) {
[356] Fix | Delete
$line_items_info[] = array(
[357] Fix | Delete
'type' => 'taxes_total',
[358] Fix | Delete
'title' => __( 'Taxes', 'woocommerce' ),
[359] Fix | Delete
'amount' => wc_price( $total_taxes, $get_price_args ),
[360] Fix | Delete
);
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
$is_order_failed = $order->has_status( 'failed' );
[364] Fix | Delete
[365] Fix | Delete
$line_items_info[] = array(
[366] Fix | Delete
'type' => 'amount_paid',
[367] Fix | Delete
'title' => $is_order_failed ? __( 'Amount', 'woocommerce' ) : __( 'Amount Paid', 'woocommerce' ),
[368] Fix | Delete
'amount' => wc_price( $order->get_total(), $get_price_args ),
[369] Fix | Delete
);
[370] Fix | Delete
[371] Fix | Delete
$payment_info = $this->get_woo_pay_data( $order );
[372] Fix | Delete
[373] Fix | Delete
return array(
[374] Fix | Delete
'order' => $order,
[375] Fix | Delete
'constants' => array(
[376] Fix | Delete
'font_size' => self::FONT_SIZE,
[377] Fix | Delete
'margin' => self::MARGIN,
[378] Fix | Delete
'title_font_size' => self::TITLE_FONT_SIZE,
[379] Fix | Delete
'footer_font_size' => self::FOOTER_FONT_SIZE,
[380] Fix | Delete
'line_height' => self::LINE_HEIGHT,
[381] Fix | Delete
'icon_height' => self::ICON_HEIGHT,
[382] Fix | Delete
'icon_width' => self::ICON_WIDTH,
[383] Fix | Delete
),
[384] Fix | Delete
'texts' => array(
[385] Fix | Delete
'receipt_title' => $receipt_title,
[386] Fix | Delete
'amount_paid_section_title' => $is_order_failed ? __( 'Order Total', 'woocommerce' ) : __( 'Amount Paid', 'woocommerce' ),
[387] Fix | Delete
'date_paid_section_title' => $is_order_failed ? __( 'Order Date', 'woocommerce' ) : __( 'Date Paid', 'woocommerce' ),
[388] Fix | Delete
'payment_method_section_title' => __( 'Payment method', 'woocommerce' ),
[389] Fix | Delete
'payment_status_section_title' => __( 'Payment status', 'woocommerce' ),
[390] Fix | Delete
'payment_status' => $is_order_failed ? __( 'Failed', 'woocommerce' ) : __( 'Success', 'woocommerce' ),
[391] Fix | Delete
'summary_section_title' => $summary_title,
[392] Fix | Delete
'order_notes_section_title' => __( 'Notes', 'woocommerce' ),
[393] Fix | Delete
'app_name' => __( 'Application Name', 'woocommerce' ),
[394] Fix | Delete
'aid' => __( 'AID', 'woocommerce' ),
[395] Fix | Delete
'account_type' => __( 'Account Type', 'woocommerce' ),
[396] Fix | Delete
),
[397] Fix | Delete
'formatted_amount' => wc_price( $order->get_total(), $get_price_args ),
[398] Fix | Delete
'formatted_date' => wc_format_datetime( $order->get_date_paid() ?? $order->get_date_created() ),
[399] Fix | Delete
'line_items' => $line_items_info,
[400] Fix | Delete
'payment_method' => $order->get_payment_method_title(),
[401] Fix | Delete
'show_payment_method_title' => empty( $payment_info['card_last4'] ) && empty( $payment_info['brand'] ),
[402] Fix | Delete
'notes' => array_map( 'get_comment_text', $order->get_customer_order_notes() ),
[403] Fix | Delete
'payment_info' => $payment_info,
[404] Fix | Delete
);
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
/**
[408] Fix | Delete
* Get the order data related to WooCommerce Payments.
[409] Fix | Delete
*
[410] Fix | Delete
* It will return null if any of these is true:
[411] Fix | Delete
*
[412] Fix | Delete
* - Payment method is not "woocommerce_payments".
[413] Fix | Delete
* - WooCommerce Payments is not installed.
[414] Fix | Delete
* - No intent id is stored for the order.
[415] Fix | Delete
* - Retrieving the payment information from Stripe API (providing the intent id) fails.
[416] Fix | Delete
* - The received data set doesn't contain the expected information.
[417] Fix | Delete
*
[418] Fix | Delete
* @param WC_Abstract_Order $order The order to get the data from.
[419] Fix | Delete
* @return array|null An array of payment information for the order, or null if not available.
[420] Fix | Delete
*/
[421] Fix | Delete
private function get_woo_pay_data( WC_Abstract_Order $order ): ?array {
[422] Fix | Delete
$card_info = PaymentInfo::get_card_info( $order );
[423] Fix | Delete
[424] Fix | Delete
if ( empty( $card_info ) ) {
[425] Fix | Delete
return null;
[426] Fix | Delete
}
[427] Fix | Delete
[428] Fix | Delete
// Backcompat for custom templates.
[429] Fix | Delete
$card_info['card_icon'] = $card_info['icon'];
[430] Fix | Delete
$card_info['card_last4'] = $card_info['last4'];
[431] Fix | Delete
[432] Fix | Delete
return $card_info;
[433] Fix | Delete
}
[434] Fix | Delete
}
[435] Fix | Delete
[436] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function