Need help modifying item data

I need to go through and check that the player has a wool carpet and modify its data, but every way I've gone about doing it with advancements creates a loop that ends up just breaking the whole thing and I don't know how to avoid it. Is there another way to get a better outcome?
Continue to help post