Im trying to achieve the same, Im not good with php and I get the part where I have to map the tag with category, but I already have products with tags published which are uncategorized. Will this code assign categories to already published products as well and if not what is the solution and where will the code go?