add_action( 'woocommerce_cart_calculate_fees','cod_fee' );
function cod_fee() {
    global $woocommerce;

    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;
        // get your payment method
        $chosen_gateway = WC()->session->chosen_payment_method;
        //echo $chosen_gateway;
        $fee = 17;
        if ( $chosen_gateway == 'cod' ) { //test with cash on delivery method
            WC()->cart->add_fee( 'رسوم الدفع عند الإستلام', $fee, false, '' );
        }


}