Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter toolking

    (@toolking)

    Now, i have try this (add in the functions.php):

        function calculate_totals( $and_taxes = true ) {
        do_action( 'woocommerce_order_before_calculate_totals', $and_taxes, $order );
    
        $fees_total        = 0;
        $shipping_total    = 0;
        $cart_subtotal_tax = 0;
        $cart_total_tax    = 0;
    
        $cart_subtotal = $order->get_cart_subtotal_for_order();
        $cart_total    = $order->get_cart_total_for_order();
    
        // Sum shipping costs.
        foreach ( $order->get_shipping_methods() as $shipping ) {
            $shipping_total += round( $shipping->get_total(), wc_get_price_decimals() );
        }
    
        $order->set_shipping_total( $shipping_total );
    
        // Sum fee costs.
        foreach ( $order->get_fees() as $item ) {
            $fee_total = $item->get_total();
    
            if ( 0 > $fee_total ) {
                $max_discount = round( $cart_total + $fees_total + $shipping_total, wc_get_price_decimals() ) * -1;
    
                if ( $fee_total < $max_discount && 0 > $max_discount ) {
                    $item->set_total( $max_discount );
                }
            }
            $fees_total += $item->get_total();
        }
    
        // Calculate taxes for items, shipping, discounts. Note; this also triggers save().
        if ( $and_taxes ) {
            $order->calculate_taxes();
        }
    
        // Sum taxes again so we can work out how much tax was discounted. This uses original values, not those possibly rounded to 2dp.
        foreach ( $order->get_items() as $item ) {
            $taxes = $item->get_taxes();
    
            foreach ( $taxes['total'] as $tax_rate_id => $tax ) {
                $cart_total_tax += (float) $tax;
            }
    
            foreach ( $taxes['subtotal'] as $tax_rate_id => $tax ) {
                $cart_subtotal_tax += (float) $tax;
            }
        }
    
        $order->set_discount_total( ceil( $cart_subtotal - $cart_total, wc_get_price_decimals()
     / 0.05) * 0.05 );
        $order->set_discount_tax( wc_round_tax_total( $cart_subtotal_tax - $cart_total_tax ) );
        $order->set_total( ceil($cart_total / 0.05) * 0.05 + ceil($fees_total / 0.05) * 0.05 + ceil($order->get_shipping_total() / 0.05) * 0.05 + ceil($order->get_cart_tax() / 0.05) * 0.05 + $order->get_shipping_tax(), wc_get_price_decimals() ) );
    
        do_action( 'woocommerce_order_after_calculate_totals', $and_taxes, $order );
    
        $order->save();
    
        return $order->get_total();
    }

    But it doesn’t work. I can’t see any changes.

    Thread Starter toolking

    (@toolking)

    Has anyone another idea how i can resolve this problem? 😉

    Thread Starter toolking

    (@toolking)

    Hmm.. ok.. i have try this one now:

    add_action( 'woocommerce_order_after_calculate_totals', "custom_order_after_calculate_totals", 10, 2);
        function custom_order_after_calculate_totals($order_tax, $order_total) {
          return ceil ( $order_tax / 0.05 ) * 0.05;
          return ceil ( $order_total / 0.05 ) * 0.05;
    }

    No Change.. how can i find the correct vars?
    Sorry for my Questions, but i am new in Woocommerce ^^

    Thank you

    Thread Starter toolking

    (@toolking)

    Hi Con

    Nope, it doesn’t work. Here is my Code for the Round-Solution (in Frontend, Checkout, Cart, etc. it works fine):

    add_filter('woocommerce_order_after_calculate_totals', 'after_total');
    function after_total( $total ) {
    $total = ceil ( $total / 0.05 ) * 0.05;
    return $total;
    }

    I can’t find any more.. i have try with woocommerce_edit_order_total and all there. Maybe i don’t see the right Thing?

    • This reply was modified 5 years, 9 months ago by toolking.
Viewing 4 replies - 1 through 4 (of 4 total)