• Resolved sevans917

    (@sevans917)


    Hello – for discounted price in cart, is there a way to override the global store setting of 2 decimal places, and show 3 places instead?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author algol.plus

    (@algolplus)

    hello

    you can try this code

    function adp_set_decimals(){
    	return 3;
    }
    add_action("woocommerce_before_cart", function(){
    	add_filter("wc_get_price_decimals","adp_set_decimals",123);
    });
    add_action("woocommerce_after_cart", function(){
    	remove_filter("wc_get_price_decimals","adp_set_decimals",123);
    });

    Hi Algo, is there a way to only apply the decimals for the per piece only in the cart. Also, is there a way to only apply the decimal places in the order area, only per piece.
    Thanks!

    • This reply was modified 3 years, 11 months ago by ox173.

    Good day, @ox173!

    is there a way to only apply the decimals for the per piece only in the cart.

    Could you try this?

    
    function adp_set_decimals(){
        return 3;
    }
    add_action("woocommerce_before_cart", function(){
        add_filter("wc_get_price_decimals","adp_set_decimals",123);
    });
    add_action("woocommerce_cart_contents", function(){
        remove_filter("wc_get_price_decimals","adp_set_decimals",123);
    });
    

    is there a way to only apply the decimal places in the order area, only per piece.

    Which ‘order area’ do you need exactly? And where? Checkout? Order details? Order edit page?

    Thanks for replying to me.

    It does modify the subtotal in the cart as well. Is there a way to only modify the price and not subtotal?

    In the backend, Woocommerce/orders once the order is clicked on there is the sub headings
    Item-Cost-qty-total-tax

    The part that is cost, I would like only to have 5 decimal places.

    Good day, @ox173

    It does modify the subtotal in the cart as well. Is there a way to only modify the price and not subtotal?

    Try this

    
    add_filter('woocommerce_cart_item_price', function ($price, $cart_item, $cart_item_key) {
        $product = apply_filters('woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key);
    
        $adpSetDecimals = function () {
            return 3;
        };
    
        add_filter("wc_get_price_decimals", $adpSetDecimals, 10);
        $price = WC()->cart->get_product_price($product);
        remove_filter("wc_get_price_decimals", $adpSetDecimals, 10);
    
        return $price;
    }, 10, 3);
    

    In the backend, Woocommerce/orders once the order is clicked on there is the sub headings
    Item-Cost-qty-total-tax

    The part that is cost, I would like only to have 5 decimal places.

    It makes no sense because the price in the order has already been rounded

    That was perfect. Thank You!

    Oddly the backend does not go to the 5th decimal (I modified the return to 5)

    Good day, @ox173

    You are welcome, but the last one is up to you. This is not a plugin issue.

    You were a huge help anyways. Do you do custom Development?

    Plugin Author algol.plus

    (@algolplus)

    I’m sorry, no.
    we just don’t have time for it

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Override decimal places in Cart’ is closed to new replies.