Understanding WooCommerce Build-In Geolocation/ Geo_IP classes

I would like to show/hide a fee in the WooCommerce checkout process depending on the location of the user. For this i would like to first use the IP address of the user to determine the location and later the address he enters. I came across the build-in Geolocation ability of WooCommerce with the following classes: WC_Geo_IP (https://docs.woocommerce.com/wc-apidocs/class-WC_Geo_IP.html) WC_Geo_IP_Record (https://docs.woocommerce.com/wc-apidocs/class-WC_Geo_IP_Record.html) WC_Geolocation (https://docs.woocommerce.com/wc-apidocs/class-WC_Geolocation.html) I'm able to get the users IP address with: $geolocation = new WC_Geolocation(); $ipaddress = $geolocation->get_ip_address(); But i …
Category: Web

Extending WP Query: Custom geolocation meta values work, but tax_query breaks

I've built a custom query for geolocation searches. I'm saving lat and lng within each custom post type as a meta value. My query extension returns results successfully when lat and lng are the only search variables. Problem: I would like to also add tax_queries to my query to further select posts Class to extend query: class WP_Query_Geo extends WP_Query { function __construct( $args = array() ) { if(!empty($args['lat'])) { $this->lat = $args['lat']; $this->lng = $args['lng']; $this->distance = $args['distance']; $this->lat_meta_name …
Category: Web

Wordpress url By country code?

I want to add country code to wordpress url by getting user ip address, which should be implemented dynamically. For example if user is from Australia, all website url will be like below: http://test.com/au htttp://test.com/au/contact For example if user is from USA, all website url will be like below: http://test.com/us htttp://test.com/us/contact
Category: Web

Post queries by latitude and longitude

I am struggling with getting post queries by coordinates. I have meta fields map_lat and map_lng for almost all post types. I am trying to return posts from one custom post type ("beaches" in this example): function get_nearby_locations($lat, $long, $distance){ global $wpdb; $nearbyLocations = $wpdb->get_results( "SELECT DISTINCT map_lat.post_id, map_lat.meta_key, map_lat.meta_value as locLat, map_lng.meta_value as locLong, ((ACOS(SIN($lat * PI() / 180) * SIN(map_lat.meta_value * PI() / 180) + COS($lat * PI() / 180) * COS(map_lat.meta_value * PI() / 180) * COS(($long …
Category: Web

Inserting data with Geometry field

I am trying to insert data which contains a POINT field. I am using the $wpdb->insert method but when generating the SQL it is wrapping the POINT in quotes. global $wpdb; $table = $wpdb->base_prefix . 'points'; $Data = array( 'Title' => $this->Title, 'gPoint' => sprintf("POINT(%s,%s)",$this->Lng, $this->Lat), 'Lat' => $this->Lat, 'Lng' => $this->Lng ); if (!$wpdb->insert($table,$Data)) throw new Exception($wpdb->last_error); This is the SQL generated. If I take the quotes from around the POINT field, the query will run. INSERT INTO `wp_points` …
Category: Web

Countrywise Post View

Can I set countrywise post view? Think you are from Russia and you’ll see from Russia category post only, and another user from Japan, he’ll see Japan posts only on the same page, provably in homepage. How can I do this? Thanks Also, how can I set random post-show rather than selecting a specific post category? Is this possible?
Category: Web

Shortcodes in billing fields doesn't work

WooCommerce: 3.5.1 WordPress: 4.9.8 I want to set automaticly billing fields with data from GeoIP shortcodes, but it doesn't work. add_filter( 'woocommerce_checkout_fields', 'set_checkout_field_input_value_default' ); function set_checkout_field_input_value_default($fields) { $fields['billing']['billing_city']['default'] = '[geoip_detect2 property="city"]'; $fields['billing']['billing_state']['default'] = '[geoip_detect2 property="mostSpecificSubdivision"]'; return $fields; } This solution didn't help: Shortcode not working inside html input Output <input type="text" class="input-text " name="billing_city" id="billing_city" placeholder="" value="[geoip_detect2 property="city"]" autocomplete="address-level2">
Category: Web

Geotargeting plugins never work

I need to either hide or show some content within pages to specific countries. However, every single WP Geotargeting plugin I have used has failed. I have checked version compatibility, checked out a few paid and free options and all result in the same thing. What happens is the content I am trying to "show" in another country hides for me accordingly but when using a VPN, or asking a friend in said country (Tested in Japan, Germany, Croatia, and …
Category: Web

Implementing geotargeting while using a single database

I'm working on a Wordpress site with a large amount of users in multple countries (UK, US, and sever African countries - Nigeria, Kenya etc). All our content is in English and we don't have the ability yet to re-do content for other areas. We do however have some small bits of content we'd like to show in certain areas of our site (free bets and special offers) dependant on country. We've tried using server side detection of the user's …
Category: Web

Ip2location plugin in my template header?

I am using Ip2location plugin to pull state data based on Ip address into my post. This is easy you install the plugin and then just use {ip:regionName} in the post or page editor. But I want to print this information in my template header file right beside the title is this possible and if so how do I go about this? This is how the header php looks like in the template <?php $def_header_text = esc_html__( 'This is Header …
Category: Web

Dynamic Content w/ geolocation in WP?

I'm really just looking for ideas and guidance while foraging for memory processing in the WordPress CMS Divi Structure. My company is in need of a good ContentPlaceholder solution. True to the MVC thinking we need to minimize the creation of redundant resources and yet create a national website that serves the regional concerns of different states. We are thinking of using geolocation (Google reverse lookup) but it has to allow standard users to add/manage the state dependant content blocks …
Category: Web

Finding all results from database within 500 miles of the given latitude and longitude

I am stuck into this problem where the main requirement is to find all results from the database which are within 500 miles of the given latitude and longitude. I have stored the lati and longi into the post_meta along with the zip code of those latitude and longitude now the idea is that when ever user searches for any zip code and select the miles from the drop down all the results matching that query should come for instance. …
Category: Web

Extracting Distance from FacetWP Proximity Function to Display in Wordpress Template

I am quite new to Wordpress & Php coding in general, I have a relatively simple theme that I have been working with that contains a custom post type that stores latitude and longitude. Each post is a listing a hotel listing within a directory. The theme I am using also integrates with FacetWP the faceting plugin for WordPress. It is possible for the user to search the site by typing a location of locating themselves, this happens using Googles …
Category: Web

Add post location with mile radius allowing search

I have a custom post type (CPT) called directory. Within this CPT there are taxonomies such as builder, plumber, painter etc. I would like to be able to add a location and a distance radius where the service is available. Example 1 A post (A) has a location of London and a mile radius of 70 miles. If a user searches for builder in cambridge then post A will appear in the search results. Example 2 A post (A) has …
Category: Web

Optimizing a Proximity-based Store Location Search on a Shared Web Host?

I've got a project where I need to build a store locator for a client. I'm using a custom post type "restaurant-location" and I have written the code to geocode the addresses stored in postmeta using the Google Geocoding API (heres the link that geocodes the US White House in JSON and I've stored the latitude and longitude back to custom fields. I've written a get_posts_by_geo_distance() function that returns a list of posts in order of those which are closest …
Category: Web

Anyway to have google maps display multiple AND unique locations per individual posts/pages?

Having the hardest time finding a solution to a big problem. So far I can't find any plugins that are capable of doing this. I have a site where each post needs to have it's own google map that pulls from a list of locations that are unique to THAT map being displayed on THAT post and displays stores that are around a typed in zip code or address for that sell the displayed item in that post. The trouble …
Category: Web

How can I implement a location based (zip code) search in WordPress?

I am working on a local business directory site that will use custom post types for the business entries. One of the fields will be "Zip Code." How can I set up a location based search? I'd like visitors to be able to enter their zip code and choose a category and show all the businesses withing a certain radius, or all the businesses ordered by distance. I saw a couple plugins that claim to do this but they don't …
Category: Web

Geo Mashup Maps show only specified categories

I'm using the Geo Mashup plugin to display maps on my site. I've changed a pages template, so it now only lists pages from certain categories instead of listing them all, which has now effected my global map to only show maps from the first categories I specify should be listed. I'm using: <?php echo GeoMashup::map(); ?> to show the map. Is there a way to give the map a list of categories it should be displaying? I can't find …
Category: Web

How to build a map with markers from single posts?

I'm writing a blog which is currently hosted at Wordpress.com. My blog posts often contain content from different cities in my country. Now I'd like to include some kind of geoposition in my blog. Furthermore there should be another site with a map (optimal solution would be an OpenStreetmap) and markers which are at the geoposition and link to that specific post. Currently I have no idea if this is possible at all and how to realise it. How can …
Category: Web

Geographical proximity query using post_meta

I realise this might be an inefficient query, but I'm trying to grab latitude and longitude values from the post_meta table that are connected to posts to figure out the proximity of the posts to a specific latitude and longitude. The pinpoint location is 36.555555, 139.731111 I've put together the following query, (based on the post here) but I'm having trouble debugging it. SELECT ID, ( 6371 * acos ( cos ( radians(36.555555 ) * cos( radians( CAST(latitude.meta_value AS DECIMAL) …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.