diff --git a/changelog/fix-9553-use-tax-inclusive-prices-pmme b/changelog/fix-9553-use-tax-inclusive-prices-pmme new file mode 100644 index 00000000000..9c76e73ddfa --- /dev/null +++ b/changelog/fix-9553-use-tax-inclusive-prices-pmme @@ -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. diff --git a/includes/class-wc-payments-payment-method-messaging-element.php b/includes/class-wc-payments-payment-method-messaging-element.php index 6270b99e912..aeffbc78c61 100644 --- a/includes/class-wc-payments-payment-method-messaging-element.php +++ b/includes/class-wc-payments-payment-method-messaging-element.php @@ -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, ]; }