/var/www/html_it/wp-content/plugins/woocommerce/src/Internal/Email/OrderPriceFormatter.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
 * OrderPriceFormatter class file.
 */

declare( strict_types );

namespace 
Automattic\WooCommerce\Internal\Email;

use 
WC_Abstract_Order;
use 
WC_Order_Item;

/**
 * Helper class for formatting prices in order emails.
 *
 * @internal Just for internal use.
 */
class OrderPriceFormatter {

    
/**
     * Gets item subtotal - formatted for display in emails.
     *
     * @param WC_Abstract_Order $order Order instance.
     * @param WC_Order_Item     $item Item to get unit price from.
     * @param string            $tax_display 'incl' or 'excl' tax display mode.
     * @return string Formatted item subtotal.
     */
    
public static function get_formatted_item_subtotalWC_Abstract_Order $orderWC_Order_Item $itemstring $tax_display ): string {
        
$includes_tax  'excl' !== $tax_display;
        
$item_subtotal $order->get_item_subtotal$item$includes_tax );
        return 
self::format_price$order$item_subtotal$includes_tax );
    }

    
/**
     * Helper method to format price with or without tax.
     *
     * @param WC_Abstract_Order $order Order instance.
     * @param float             $amount The amount to format.
     * @param bool              $includes_tax Whether to include tax in the formatted price.
     * @return string Formatted price string.
     */
    
private static function format_priceWC_Abstract_Order $orderfloat $amountbool $includes_tax ): string {
        return 
wc_price(
            
$amount,
            array(
                
'ex_tax_label' => ( ! $includes_tax && $order->get_prices_include_tax() ) ? 0,
                
'currency'     => $order->get_currency(),
            )
        );
    }
}