In this paper, a new computational method based on the Legendre wavelets (LWs) is proposed for solving a class of variable‐order fractional optimal control problems (V‐FOCPs). To do this, a new operational matrix of variable‐order fractional integration (OMV‐FI) in the Riemann‐Liouville sense for the LWs is derived and used to obtain an approximate solution for the problem under study. Along the way the hat functions (HFs) are introduced and employed to derive a general procedure to compute this matrix. In the proposed method, the variable‐order fractional dynamical system is transformed to an equivalent variable‐order fractional integro‐differential dynamical system, at first. Then, the highest integer order of the derivative of the state variable and the control variable are expanded by the LWs with unknown coefficients. Next, the OMV‐FI in the the Riemann‐Liouville sense together with some properties of the LWs are employed to achieve a nonlinear algebraic equation in place of the performance index and a nonlinear system of algebraic equations in place of the dynamical system in terms of the unknown coefficients. Finally, the method of constrained extremum is applied which consists of adjoining the constraint equations derived from the given dynamical system to the performance index by a set of undetermined Lagrange multipliers. As a result, the necessary conditions of optimality are derived as a system of algebraic equations in the unknown coefficients of the state variable, control variable and Lagrange multipliers. Furthermore, the efficiency and accuracy of the proposed method are demonstrated for some concrete examples. The obtained results show that the proposed method is very efficient and accurate.