Skip to content

Commit 1120533

Browse files
committed
Update receipt.php
1 parent 2d69829 commit 1120533

File tree

1 file changed

+55
-13
lines changed

1 file changed

+55
-13
lines changed

templates/receipt.php

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,49 +216,91 @@
216216
?>
217217
</td>
218218
<td><?php echo esc_html( $item->get_quantity() ); ?></td>
219-
<td><?php echo \is_object( $product ) && method_exists( $product, 'get_price' ) ? wp_kses_post( wc_price( $product->get_price() ) ) : ''; ?></td>
220-
<td><?php echo wp_kses_post( wc_price( $item->get_total() ) ); ?></td>
219+
<td><?php
220+
$tax_display = get_option( 'woocommerce_tax_display_cart' );
221+
if ( 'excl' === $tax_display ) {
222+
echo wp_kses_post( wc_price( $item->get_subtotal() / $item->get_quantity() ) );
223+
} else {
224+
echo wp_kses_post( wc_price( $item->get_subtotal_tax() / $item->get_quantity() + $item->get_subtotal() / $item->get_quantity() ) );
225+
}
226+
?></td>
227+
<td><?php
228+
$tax_display = get_option( 'woocommerce_tax_display_cart' );
229+
if ( 'excl' === $tax_display ) {
230+
echo wp_kses_post( wc_price( $item->get_total() ) );
231+
} else {
232+
echo wp_kses_post( wc_price( $item->get_total() + $item->get_total_tax() ) );
233+
}
234+
?></td>
221235
</tr>
222236
<?php } ?>
223237
</tbody>
224238
<tfoot>
225239
<tr>
226240
<th colspan="3"><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?></th>
227-
<td><?php echo wp_kses_post( wc_price( $order->get_subtotal() ) ); ?></td>
241+
<td><?php
242+
$tax_display = get_option( 'woocommerce_tax_display_cart' );
243+
if ( 'excl' === $tax_display ) {
244+
echo wp_kses_post( wc_price( $order->get_subtotal() ) );
245+
} else {
246+
echo wp_kses_post( wc_price( $order->get_subtotal() + $order->get_subtotal_tax() ) );
247+
}
248+
?></td>
228249
</tr>
229250
<?php if ( $order->get_shipping_total() > 0 ) { ?>
230251
<tr>
231252
<th colspan="3"><?php esc_html_e( 'Shipping', 'woocommerce' ); ?></th>
232-
<td><?php echo wp_kses_post( wc_price( $order->get_shipping_total() ) ); ?></td>
253+
<td><?php
254+
if ( 'excl' === $tax_display ) {
255+
echo wp_kses_post( wc_price( $order->get_shipping_total() ) );
256+
} else {
257+
echo wp_kses_post( wc_price( $order->get_shipping_total() + $order->get_shipping_tax() ) );
258+
}
259+
?></td>
233260
</tr>
234261
<?php } ?>
235262
<?php foreach ( $order->get_fees() as $fee ) { ?>
236263
<tr>
237264
<th colspan="3"><?php echo esc_html( $fee->get_name() ); ?></th>
238-
<td><?php echo wp_kses_post( wc_price( $fee->get_total() ) ); ?></td>
265+
<td><?php
266+
if ( 'excl' === $tax_display ) {
267+
echo wp_kses_post( wc_price( $fee->get_total() ) );
268+
} else {
269+
echo wp_kses_post( wc_price( $fee->get_total() + $fee->get_total_tax() ) );
270+
}
271+
?></td>
239272
</tr>
240273
<?php } ?>
241274
<?php if ( $order->get_total_discount() > 0 ) { ?>
242275
<tr>
243276
<th colspan="3"><?php esc_html_e( 'Discount', 'woocommerce' ); ?></th>
244-
<td><?php echo wp_kses_post( wc_price( $order->get_total_discount() ) ); ?></td>
277+
<td><?php
278+
// Discounts are always displayed as positive numbers
279+
if ( 'excl' === $tax_display ) {
280+
echo wp_kses_post( wc_price( $order->get_total_discount( false ) ) );
281+
} else {
282+
echo wp_kses_post( wc_price( $order->get_total_discount( true ) ) );
283+
}
284+
?></td>
245285
</tr>
246286
<?php } ?>
247-
<?php if ( wc_tax_enabled() ) { ?>
248-
<?php if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) { ?>
249-
<?php foreach ( $order->get_tax_totals() as $code => $tax ) { ?>
287+
<?php
288+
// Only show tax rows if we're showing prices excluding tax
289+
if ( 'excl' === $tax_display && wc_tax_enabled() ) {
290+
if ( 'itemized' === get_option( 'woocommerce_tax_total_display' ) ) {
291+
foreach ( $order->get_tax_totals() as $code => $tax ) { ?>
250292
<tr>
251293
<th colspan="3"><?php echo esc_html( $tax->label ); ?></th>
252294
<td><?php echo wp_kses_post( wc_price( $tax->amount ) ); ?></td>
253295
</tr>
254-
<?php } ?>
255-
<?php } else { ?>
296+
<?php }
297+
} else { ?>
256298
<tr>
257299
<th colspan="3"><?php echo esc_html( WC()->countries->tax_or_vat() ); ?></th>
258300
<td><?php echo wp_kses_post( wc_price( $order->get_total_tax() ) ); ?></td>
259301
</tr>
260-
<?php } ?>
261-
<?php } ?>
302+
<?php }
303+
} ?>
262304
<tr>
263305
<th colspan="3"><?php esc_html_e( 'Total', 'woocommerce' ); ?></th>
264306
<td><?php echo wp_kses_post( wc_price( $order->get_total() ) ); ?></td>

0 commit comments

Comments
 (0)