You can't trust IP addresses at all: not only can they change (as the user moves around on a mobile, or laptop, or when the router is reset), they are also shared by all users connected to a single router - so all employees at the same company would share the same IP address.
Instead, use cookies to store the tracking id or a shopping cart on the user device - that way it moves with the user, he doesn't lose it, and his purchases aren't shared with other users. There is loads of info complete with example code available via Google:
cookies php[
^]