This paper presents a numerical method for solving optimal control problems including non-linear Volterra integral equations. The method is based upon generalized hat functions (HFs). Using the properties of HFs and associated operational matrices, optimal control problem is converted to an optimization problem. Furthermore, error analysis of the proposed method is studied. Illustrative examples are included to demonstrate the validity and applicability of the approach.