Skip to content

Instantly share code, notes, and snippets.

@timersys
timersys / countries.php
Last active November 24, 2022 13:07
Change dropdown widget country names
<?php
add_filter('geot/dropdown_widget/countries', function($countries) {
foreach( $countries as $i => $c ) {
if( $c->iso_code == 'US' ) {
$countries[$i]->country = 'USA';
}
if( $c->iso_code == 'GB' ) {
@timersys
timersys / geot-disable-builder.php
Created November 17, 2022 12:46
Disable builder integrations with GeotargetingWP plugin
<?php
/**
* Add this file in the wp-content/mu-plugins/ folder. If the folder doesn't exist simply create it.
* Uncomment the line for you builder and comment out the rest
**/
add_filter( 'geot/deactivate_divi_integration', '__return_true' );
//add_filter( 'geot/deactivate_beaver_integration', '__return_true' );
//add_filter( 'geot/deactivate_elementor_integration', '__return_true' );
//add_filter( 'geot/deactivate_fusion_integration', '__return_true' );
@timersys
timersys / functions.php
Last active September 23, 2021 16:39
Custom country widget for GeotargetingWP
<?php
/*
* The following code serves as an example and could be copied over to your theme's functions.php file
* Ideally you want to separate your javascript files and load them separatly.
* This example it's based on the following HTML structure:
* <a href="#" data-iso="US" class="geot-countries">United States</a> - <a href="#" data-iso="AR" class="geot-countries">Argentina</a>
*/
add_action('wp_footer', 'my_custom_geot_widget' );
@timersys
timersys / functions.php
Created July 9, 2021 13:44
Set custom data based on urls on GeotargetingWP
<?php
class GeotWP_Url_Location {
public function __construct() {
add_filter( 'geot/cancel_query', [ $this, 'set_custom_data' ] );
}
/**
* Check if url is set and modify data
@timersys
timersys / functions.php
Created May 27, 2021 19:14
Change the GeotargetingWP translation file location
<?php
function wpse159536_override_mofile_path( $mofile, $domain ){
if( 'geot' == $domain ){
$mofile = WP_LANG_DIR . '/plugins/' . basename( $mofile );
}
return $mofile;
}
add_filter( 'load_textdomain_mofile', 'wpse159536_override_mofile_path', 10, 2);
@timersys
timersys / functions.php
Created May 26, 2021 14:54
Changing location in GeotargetingWP using URL parameters or querys tring
<?php
/**
* Allow users to change location with query string like this
* https://yourdomain.com?geot_country=US
**/
add_action( 'init', 'change_geolocation_with_url' );
function change_geolocation_with_url(){
if( ! isset( $_GET['geot_country'] ) ) {
return;
}
@timersys
timersys / app.js
Last active May 10, 2021 12:48
Access Javascript geo info in GeotargetingWP
$(document).on('geotwp_ajax_success', function(e, data) {
if( typeof data.geo != 'undefined') {
// create a custom cookie with zip value and 999 days duration
GeotCreateCookie('geot_switcher', data.geo.city.data.zip, 999);
// Add a marker in a custom google map
if( data.geo.geolocation.data.latitude && data.geo.geolocation.data.longitude && jQuery('#geot-map').length != 0 ) {
var stanton = {lat: parseFloat(data.geo.geolocation.data.latitude), lng: parseFloat(data.geo.geolocation.data.longitude)};
add_marker(stanton);
}
@timersys
timersys / file.php
Created April 23, 2021 16:33
AJAX PHP functions in GeotargetingWP
<?php
/**
* Practical example on how to use ajax php functions
**/
$html = '<p>This is your HTML you want to apply geotargeting, if you have complex and large content you could use ob_start() and ob_get_clean() to fill this variable with the HTML</p>';
$html_world = '<p>Some other HTML for everyone except US and CA</p>';
// We echo the part for and US,CA. Javascript will take care of hide or show the $html
echo ajax_geotwp_filter( ['country' => 'US,CA'],$html);
<?php
// geot_user_country
// Return object of current user country details
$country = geot_user_country();
echo $country->name;
echo $country->isoCode;
//geot_country_code
// return current user country code
@timersys
timersys / functions.php
Created January 19, 2021 14:11
Wrap functions to be safe
<?php
if( function_exists( 'geot_target' ) ) {
if( geot_target( 'AR' ) ) {
echo 'Only show to Argentina';
}
}