This did the trick.
(defun jarfar/org-update-all-statistics-cookies ()
"Update all statistics cookies in org buffer."
(when (string-equal major-mode "org-mode")
(org-update-statistics-cookies t)))
(add-hook 'buffer-list-update-hook 'jarfar/org-update-all-statistics-cookies)
(advice-add 'save-buffer :before (lambda (&rest args) (jarfar/org-update-all-statistics-cookies)))
EDIT
Sadly this messes things up.
When cookies get updated the file is marked as modified even if there were no changes, so it cause constant problems with unsaved changes.
It turned out that it's better to refresh cookies manually.
C-c C-c
, the cookie gets updated automatically and you don't have to run a manual update. Similarly usingC-c C-t
(or the fast-todo-selection keys) to change a TODO item state, will update the cookie automatically.