To have ID2 (product 2) show a message “Thank you for this purchase.” , is ab it odd, what about people who buy product 1 (ID1), they dont get that warming message?. I think what you’re trying to do is way beyond my expertise, but if i was in your position where i want each cart ID to show a specific message, i’de think of it this way:
each ID is linked to an Item Number and product. So if ID1 is linked to a product “orange”. So then you go and find the wordpress post id of “orange”, and then when people add orange to their cart, and checkout, you can modify the checkout page itself with some php rule like “if post id= orange, then echo this message “thanks for buying an orange”.
But anyway, if u want anything to show at the checkout, you’re going to have to add the code to your Pages > Checkout page and install a wordpress plugin that lets you execute PHP code in pages/posts.