I am using 0 decimals under wc-settings&tab=general
which is working fine for my usecase. But now adding a discount for a specific payment method which is set to 10 percent at the moment.
For an 12 usd item it rounds the discount value to 1 – which reuslt in an a total of 11 instead of 10.8 due to the 0 decimals settings mentioned before.
The closest i came up with was the following filter, but resultet in shipping cost going from 23 to 23.23 usd too. Any idea how to apply the 2 decimals only to the discount amount without interfering elsewhere?
// Change woo settings from 0 at the moment in backend to 2 decimals for wallet payment
add_filter( 'wc_get_price_decimals', 'custom_price_decimals_for_wallet_s0dgPHq2',10,1);
function custom_price_decimals_for_wallet_s0dgPHq2( $decimals ) {
// Check if we are on the front-end and WooCommerce session is available
if ( !is_admin() && WC()->session && isset(WC()->session->chosen_payment_method) ) {
// Only change decimal places if the chosen payment method is wallet
if ( WC()->session->chosen_payment_method === 'wallet' ) {
// Set to 2 decimals for wallet payments
$decimals = 2;
return $decimals;
}
// Return the default value for other cases
return $decimals;
}
}