Site logo

Archived topic

Show element based on user selection (cookie)

1 reply · Started by Andrew on June 28, 2022

Viewing posts 1–2 of 2

Hey guys.

I'm trying to work out a way to display an element based on user selection. When a user lands at the site they will be prompted to select their location (probably stored as a cookie). I want to display the appropriate sales rep contact card on product pages throughout the site. I need to find a way for the site to read the users choice and display the correct element.

Not sure if this is possible so am looking for ideas.

Cheers!

Hi Andrew,

You could probably try using a plugin. Tried to do some searching, and it seems a plugin called Geoplugin can retrieve the location through PHP: https://stackoverflow.com/questions/5398674/get-users-current-location#:~:text=40-,%3C%3Fphp,-%24user_ip%20%3D%20getenv

Also see: https://www.codegrepper.com/code-examples/php/get+user+location+php

Then you can try to use filter generate_block_element_display and create a conditional statement based on the location.

Reference: https://docs.generatepress.com/article/generate_element_display/

Hope this helps!

This archived topic is closed to new replies.