This is a quite easy you just have to add:
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() : "\<CR>"
you have to put this line inside init.lua
However, If you use the auto paring package (https://github.com/windwp/nvim-autopairs) with COC it's not going to work.
to check whether it's going to work or not simple run
:verbose imap <CR>
after you install and setup your package
If nothing is there you are good to go and use my imap that I provide.
If there is any key map that is already binding to the CR (which means enter BTW) then, you have to remap it on the package or use a different key than enter.
In my case, windwp auto paring takes the enter key and that leads to an error.
The solution is to use COC auto pair.
just run :CocInstall coc-pairs and you are good to go.