Skip to content

Commit

Permalink
Use tax inclusive amounts in PMME calculations to match displayed pri…
Browse files Browse the repository at this point in the history
…ces (#9583)
  • Loading branch information
danielmx-dev authored Oct 18, 2024
1 parent 23ba546 commit 7f8cad7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-9553-use-tax-inclusive-prices-pmme
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

The amounts used by the PMMEs will match the displayed price of the product regardless of the tax settings.
29 changes: 27 additions & 2 deletions includes/class-wc-payments-payment-method-messaging-element.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,42 @@ public function init() {
$product_variations = [];

if ( $product ) {
$get_price_fn = function ( $product ) {
return $product->get_price();
};
if ( wc_tax_enabled() && $product->is_taxable() ) {
if (
wc_prices_include_tax() &&
(
get_option( 'woocommerce_tax_display_shop' ) !== 'incl' ||
WC()->customer->get_is_vat_exempt()
)
) {
$get_price_fn = function ( $product ) {
return wc_get_price_excluding_tax( $product );
};
} elseif (
get_option( 'woocommerce_tax_display_shop' ) === 'incl'
&& ! WC()->customer->get_is_vat_exempt()
) {
$get_price_fn = function ( $product ) {
return wc_get_price_including_tax( $product );
};
}
}
$price = $get_price_fn( $product );
$product_variations = [
'base_product' => [
'amount' => WC_Payments_Utils::prepare_amount( $product->get_price(), $currency_code ),
'amount' => WC_Payments_Utils::prepare_amount( $price, $currency_code ),
'currency' => $currency_code,
],
];
foreach ( $product->get_children() as $variation_id ) {
$variation = wc_get_product( $variation_id );
if ( $variation ) {
$price = $get_price_fn( $variation );
$product_variations[ $variation_id ] = [
'amount' => WC_Payments_Utils::prepare_amount( $variation->get_price(), $currency_code ),
'amount' => WC_Payments_Utils::prepare_amount( $price, $currency_code ),
'currency' => $currency_code,
];
}
Expand Down

0 comments on commit 7f8cad7

Please sign in to comment.