The significance of childbearing opportunity cost (COC) on fertility preference and fertility behaviors has been recognized widely, but the quantitative analysis is still under-developed. In this paper, fertility opportunity cost is regarded as a counterfactual income cost of fertility behavior, and the machine learning algorithm is used to measure women’s fertility opportunity cost and investigate the heterogeneity of fertility opportunity cost. Through regression model, the marginal effect of fertility opportunity cost on fertility intention and fertility quantity is identified. The results show that the COC for male births is lower than that for female births. The women with higher education income levels have lower obsolute and relative opportunity costs of childbearing. This heterogeneity is closely related to the access to maternity insurance. Low-income female laborers are largely outside the coverage of maternity insurance and have higher COC. The further analysis reveals that one unit of increasement in absolute COC will lead to the intentions to have two or more children decrease by 1.6 percent and 1.5 percent, respectively, and the actual number of births decreases by 1.1 percent. The findings make good reference for understanding the future fertility trend.