• Resolved nick8182

    (@nick8182)


    hello to everything, there is the code to apply a fixed cost only for the payment “Cash on Delivery” ?

    I found this code, it works but applies a fixed cost to all payment methods …. and I do not know how to make it work only with the payment Cash on Delivery

    add_action( ‘woocommerce_cart_calculate_fees’,’endo_handling_fee’ );
    function endo_handling_fee() {
    global $woocommerce;

    if ( is_admin() && ! defined( ‘DOING_AJAX’ ) )
    return;

    $fee = 5.00;
    $woocommerce->cart->add_fee( ‘Handling’, $fee, true, ‘standard’ );
    }

    Thanks for your help

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Mike M. a11n

    (@mikedmoore)

    Automattic Happiness Engineer

    Hi there,

    Since your code is working to add fees to all payment gateways, you’ll just need to wrap it in a conditional statement that checks the chose payment method. Something like this should work:

    
    $chosen_gateway = WC()->session->chosen_payment_method;
     
    if ( $chosen_gateway == 'cod' ) { 
    
    //add fee here
    		
    }
    
    Plugin Support AW a11n

    (@slash1andy)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – but if you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WooCommerce : Add fee for Cash on Delivery payment method (cod)’ is closed to new replies.