If what you mean is detecting when a non-registered user has purchased from the site before, this is where things like
cookies[
^] would be useful. If a customer purchases a product from your website you could store the IDs of the products in a cookie, and when they register you could check whether the cookie exists and pull in the relevant information.
An alternative to using cookies would be to use
localStorage[
^] which is an alternative method for storing data in the browser. Using this would require you to send the product information to the server during the sign-up process.
Just be aware that storing data in either of these methods is
no guarantee that you'll be able to get the product purchase information. If the user chooses to use another browser, clear their browser data, buy or register in an incognito mode, or even sign up using a different device, then you won't have access to that information.
It could be suggested that you could require an email address during the shopping check-out process, and then link any purchased products to the account during sign up. However, this would be a bad idea, not only due to
regulation restrictions[
^], but a malicious actor could sign up an account and use someone else's email to access their purchase history.