Sometimes it’s useful for developer to determine if user is viewing his store using mobile device or desktop computer. For example to load mobile-specific scripts or styles – or if there is a need to enable a feature only on mobile/desktop.
Fortunately PrestaShop comes with several functions, helpful for working with that kind of task. Those functions are based on Mobile_Detect library (https://github.com/serbanghita/Mobile-Detect).
Everything is placed in
classes/Context.php file. If you study the content of this class, you can see all functions responsible for detecting device of your store visitor.
To check user device, you’ll need to call (from PHP file):
FUNCTION_NAME can be any of following:
- isMobile() – check if user’s device is mobile/smartphone
- isTablet() – check if user’s device is tablet
- getDevice() – return a number which is connected to user’s device. [1 – for computer] [2 – for tablet] [4 – for mobile]. It’s good if you want to add conditions in your code for one or more devices.
There are more functions in Context class but I think those three are the most important in terms of checking your visitor’s device.