1

I'm using WooCommerce for my e-commerce store and I'd like to know if there is some option, how to get a total price (fee) of shipping and total price (fee) of payment methods and their sum on Checkout page. (shipping fee + payment fee = result). I found out how to get a shipping fee without currency symbol ($), which is what I was looking for. But I can't find out the solution how to get payment fee (total), because sometimes when you use Cash-on-delivery tax, you need to get sum of all payment method fees. And so on I need to get sum of shipping fees and payment method fees.

For now I got something like the code, which is mentioned below, but it's not as good as I need.

<?php echo $shipping_price = WC()->session->get('cart_totals') €['shipping_total'];?> 
    <?php foreach ( WC()->cart->get_fees() as $fee ) : ?>,
        <?php $checkout_fee = wc_cart_totals_fee_html( $fee ); 
                    
           echo $checkout_fee;
                    
        ?>
<?php endforeach; ?>

With the code above I get both values, but one is without currency symbol and the second one is with currency symbol and also placed in foreach loop. So I can't get a sum of them.

If anybody could help, I'd be very grateful.

Thanks.

aynber
  • 22,380
  • 8
  • 50
  • 63
StepanP
  • 33
  • 4

1 Answers1

2

Instead you could use directly some related WC_Cart methods, to get what you expect, like:

<?php 
    $shipping_total = WC()->cart->get_shipping_total() + WC()->cart->get_shipping_tax();
    $fees_total     = WC()->cart->get_fee_total() + WC()->cart->get_fee_tax();

    // Output formatted total
    echo '<p>Total shipping and fees: ' . wc_price( $fees_total + $shipping_total ) . '</p>';  
?>
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • First solutions returns me an error, but the second one is what I was looking for and it works. Thanks for your help! – StepanP Feb 22 '21 at 14:30
  • yes, I will do it, but I wanted to say in the code there is a mistake: wc_price( $fee_total + $shipping_total ) – there should be $fees_total instead of $fee_total, you called an empty variable. – StepanP Feb 22 '21 at 17:36