Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

php - Change number of decimals in Woocommerce cart, checkout and my account

Would it be possible to have a php code to insert in my child theme capable of passing my site to two decimal places after the comma for all the basket information subtotal total VAT Shipping the same for the checkout but also in the customer area

I would like to keep only the product to three decimal after the decimal point but the total rounded up to two decimal after the decimal point

can you help me

I am using Change number of decimals in Woocommerce cart totals answer code, for the cart and the checkout pages. It works perfectly but I am missing an info for it to work in the my order account tab.

screenshot


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For my account section use the conditional tag is_account_page(), so in the code:

add_filter( 'wc_get_price_decimals', 'change_prices_decimals', 20, 1 );
function change_prices_decimals( $decimals ){
    if( is_cart() || is_checkout() || is_account_page() )
        $decimals = 2;
    return $decimals;
}

Code goes in functions.php file of the active child theme (or active theme). It should works.

Related: Change number of decimals in Woocommerce cart totals


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...