WooCommerce: Hide Product Based on IP Address / Geolocation

There are many plugins that would allow you to do this in bulk or that would give you advanced features… but what if you just need to hide one product ID for users who are visiting your WooCommerce website from a specific country code?

This is also called “geolocation” – remember this won’t work unless you’ve enabled geolocation inside the WooCommerce general settings. Other than that, get your product ID, find out the target country 2-letter code, and this snippet will do the trick. Enjoy!

Continue reading WooCommerce: Hide Product Based on IP Address / Geolocation

WooCommerce: How to Test Geolocation?

Great question, isn’t it?

How do you make sure your shipping, taxes and currency settings are working properly when they depend on geolocation and you can only test from a single world location?

WooCommerce uses a free geolocation service called MaxMind. By default this is active via the settings but can be disabled. The set of functions (or class) that WooCommerce uses is in the /includes folder, and it’s called Class WC_Geolocation.

Continue reading WooCommerce: How to Test Geolocation?

WooCommerce: Detecting Current User Country (Geolocation)

In the redesign of Business Bloomer homepage, launched recently, I wanted to add some “personalization” to the main headline. In detail, I wanted to make use of PHP and WooCommerce inbuilt MaxMind Geolocation (when enabled from the General Settings Tab of course) to print a custom greeting on the screen.

The detection of the current user country could be very useful for other tasks, such as disabling payment gateways and shipping methods, printing country-specific content and so on. And as usual, this “detection” is done with one line of code! Continue reading WooCommerce: Detecting Current User Country (Geolocation)