• Hi, I customized the checkout page by adding a 3.5% percentage fee for Paymongo Credit Card payment gateway.

    However with my code now, it’s only calculating 3.5% of the cart total EXCLUDING shipping fee. How can I alter the code below that calculates it WITH the shipping fee? Thank you so much!

    // Adding fee for Paymongo
    
    add_action( 'woocommerce_cart_calculate_fees','ts_add_discount', 20, 1 );
    
    function ts_add_discount( $cart_object ) {
    
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) return;
    
    // Mention the payment method e.g. cod, bacs, cheque or paypal
    $payment_method = 'paymongo';
    
    // The percentage to apply
    $percent = 3.5; // 3.5%
    
    $cart_total = $cart_object->subtotal_ex_tax;
    
    $chosen_payment_method = WC()->session->get('chosen_payment_method'); //Get the selected payment method
    
    if( $payment_method == $chosen_payment_method ){
    
    $label_text = __( "PayMongo Convenience Fee (3.5%)" );
    
    // Calculating percentage
    $discount = number_format(($cart_total / 100) * $percent, 3.5);
    
    // Adding the discount
    $cart_object->add_fee( $label_text, +$discount, false );
    }
    }
    
    add_action( 'woocommerce_review_order_before_payment', 'ts_refresh_payment_method' );
    
    function ts_refresh_payment_method(){
    // jQuery
    ?>
    <script type="text/javascript">
    (function($){
    $( 'form.checkout' ).on( 'change', 'input[name^="payment_method"]', function() {
    $('body').trigger('update_checkout');
    });
    })(jQuery);
    </script>
    <?php
    }

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • In case you didn’t make it, you should try this:

    $cart_total = $cart_object->subtotal_ex_tax + $cart_object->shipping_total;

Viewing 1 replies (of 1 total)
  • The topic ‘Calculating Percentage of Total Cart Price with Shipping Fee’ is closed to new replies.