Understanding WooCommerce Build-In Geolocation/ Geo_IP classes

This is how I used WooCommerce to get the country code on a recent project, using the geolocate_ip method of the WC_Geolocation class. $country = ‘US’; if (class_exists(‘WC_Geolocation’)) { $location = WC_Geolocation::geolocate_ip(”, true, false); if (isset($location[‘country’])) { $country = $location[‘country’]; } } switch ($country) { case ‘AU’: break; case ‘US’: break: }

Geotargeting plugins never work

Although this is not the place for plugin support (or recommendations), I assume that you’ve asked the googles for ideas. A quick search reveals several sites that have documented/listed geotargeting apps. But, you say that you have friends in other countries that test it for you. Have you watched ‘live’ Google Analytics to see if … Read more

Shortcodes in billing fields doesn’t work

The “official” answer is that you need to use do_shortcode() to process the shortcode as you can’t just simply apply a shortcode within the code. Here’s your original code with the “official” do_shortcode() way: add_filter( ‘woocommerce_checkout_fields’, ‘set_checkout_field_input_value_default’ ); function set_checkout_field_input_value_default($fields) { $fields[‘billing’][‘billing_city’][‘default’] = do_shortcode( ‘[geoip_detect2 property=”city”]’ ); $fields[‘billing’][‘billing_state’][‘default’] = do_shortcode( ‘[geoip_detect2 property=”mostSpecificSubdivision”]’ ); return $fields; … Read more

Countrywise Post View

It’s possible, let’s say you want to affect all post queries like this, you will need to get the country of origin and then change the query. Given you have two categories, something like Russian news and Japanese news, you could do it basically like this: /** * Returns origin country of request if available … Read more

Geo Blocking in WordPress – how can it be implemented?

If memory serves, Bad Behavior allows to configure a few aspects of geo-blocking. There might be a few wp.org plugins tagged as security that allow to implement geo-blocking too. That said, I don’t think it’s the right approach. The best is to hop over to askapache.com. There’s tons of security-related, htaccess-based stuff over there. Geo-blocking … Read more