DeferredEmailQueue.php
1 month ago
EmailColors.php
11 months ago
EmailFont.php
1 year ago
EmailLogger.php
1 month ago
EmailStyleSync.php
11 months ago
OrderPriceFormatter.php
1 year ago
OrderPriceFormatter.php
52 lines
| 1 | <?php |
| 2 | /** |
| 3 | * OrderPriceFormatter class file. |
| 4 | */ |
| 5 | |
| 6 | declare( strict_types = 1 ); |
| 7 | |
| 8 | namespace Automattic\WooCommerce\Internal\Email; |
| 9 | |
| 10 | use WC_Abstract_Order; |
| 11 | use WC_Order_Item; |
| 12 | |
| 13 | /** |
| 14 | * Helper class for formatting prices in order emails. |
| 15 | * |
| 16 | * @internal Just for internal use. |
| 17 | */ |
| 18 | class OrderPriceFormatter { |
| 19 | |
| 20 | /** |
| 21 | * Gets item subtotal - formatted for display in emails. |
| 22 | * |
| 23 | * @param WC_Abstract_Order $order Order instance. |
| 24 | * @param WC_Order_Item $item Item to get unit price from. |
| 25 | * @param string $tax_display 'incl' or 'excl' tax display mode. |
| 26 | * @return string Formatted item subtotal. |
| 27 | */ |
| 28 | public static function get_formatted_item_subtotal( WC_Abstract_Order $order, WC_Order_Item $item, string $tax_display ): string { |
| 29 | $includes_tax = 'excl' !== $tax_display; |
| 30 | $item_subtotal = $order->get_item_subtotal( $item, $includes_tax ); |
| 31 | return self::format_price( $order, $item_subtotal, $includes_tax ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Helper method to format price with or without tax. |
| 36 | * |
| 37 | * @param WC_Abstract_Order $order Order instance. |
| 38 | * @param float $amount The amount to format. |
| 39 | * @param bool $includes_tax Whether to include tax in the formatted price. |
| 40 | * @return string Formatted price string. |
| 41 | */ |
| 42 | private static function format_price( WC_Abstract_Order $order, float $amount, bool $includes_tax ): string { |
| 43 | return wc_price( |
| 44 | $amount, |
| 45 | array( |
| 46 | 'ex_tax_label' => ( ! $includes_tax && $order->get_prices_include_tax() ) ? 1 : 0, |
| 47 | 'currency' => $order->get_currency(), |
| 48 | ) |
| 49 | ); |
| 50 | } |
| 51 | } |
| 52 |