Title: problems and more problems!
Last modified: February 15, 2018

---

# problems and more problems!

 *  Resolved [jhonatanll](https://wordpress.org/support/users/jhonatanll/)
 * (@jhonatanll)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/problems-and-more-problems-2/)
 * hello good, I’m trying to do something (in theory) simple but there’s no way!
 * The idea is to detect if the client is from 3 specific provinces and, if there
   is one, that both the prices and the buttons to add to the cart are hidden.
 * the code is the following and I can not get it to work:
 * $ip = $_SERVER[‘REMOTE_ADDR’];
    $record = geoip_detect2_get_info_from_current_ip(
   $ip); $prov = $record->mostSpecificSubdivision->isoCode;
 * function ven(){
    if ($prov == ‘A’ || $prov == ‘MU’ || $prov == ‘V’) { remove_action(‘
   woocommerce_after_shop_loop_item’, ‘woocommerce_template_loop_add_to_cart’, 20);
   remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_price’,
   10 ); remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_add_to_cart’,
   30 ); remove_action( ‘woocommerce_after_shop_loop_item_title’, ‘woocommerce_template_loop_price’,
   10 ); add_action( ‘woocommerce_single_product_summary’, ‘nuevo’, 31 ); add_action(‘
   woocommerce_after_shop_loop_item’, ‘nuevo’, 11 ); } else { return false; } }
 * function nuevo() {
    global $product; $product_type = $product->product_type; 
   switch ( $product_type ) { case ‘simple’: echo ‘[Consultar](http://tienda.inopol.es/informacion)
   <style>.woocommerce .button { display: none;}</style>’; break; case ‘variable’:
   echo ‘[Consultar](http://tienda.inopol.es/informacion)‘; break; default: echo‘
   [Consultar](http://tienda.inopol.es/informacion)‘; } }
 * add_action(‘init’, ‘ven’);
 * and thank you very much for the plugin!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Benjamin Pick](https://wordpress.org/support/users/benjamin4/)
 * (@benjamin4)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/problems-and-more-problems-2/#post-9977617)
 * I don’t know Woocommerce so I can’t help you there from the top of my head …
   
   But I think it would be simpler to go the CSS route: [https://github.com/yellowtree/wp-geoip-detect/wiki/API-Usage-Examples#css-use](https://github.com/yellowtree/wp-geoip-detect/wiki/API-Usage-Examples#css-use)
   I will add the province code to the body class, then you can use the beta version
   of the plugin:
 * [https://github.com/yellowtree/wp-geoip-detect/archive/master.zip](https://github.com/yellowtree/wp-geoip-detect/archive/master.zip)
 *  Thread Starter [jhonatanll](https://wordpress.org/support/users/jhonatanll/)
 * (@jhonatanll)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/problems-and-more-problems-2/#post-9978208)
 * The code works, I deleted the geolocation code (to be applied without more) and
   do what I want, the problem is that, in the log, I get the error: “geoip_detect2_get_info_from_current_ip(),
   is not defined”.
 * Thanks for the speed and forgiveness for my bad English!
 *  [Benjamin Pick](https://wordpress.org/support/users/benjamin4/)
 * (@benjamin4)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/problems-and-more-problems-2/#post-9978434)
 * (French? I would be even worse in Spanish, sorry…)
 * It is working for me … Yes indeed you don’t need the code that you mentioned 
   above. Check the Body CSS option and then you can add the CSS rules to your template.
 * If the method call is from my plugin, which line/file is it?
 *  Thread Starter [jhonatanll](https://wordpress.org/support/users/jhonatanll/)
 * (@jhonatanll)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/problems-and-more-problems-2/#post-9978889)
 * Well, yes … Spanish hahaha
    solved! It was a small mistake of order, thank you!
 * I leave the code here in case anyone is interested in it today or in the future:
   
   add_action(‘wp_head’, ‘ven’, 5); function ven(){ $userInfo = geoip_detect2_get_info_from_current_ip();
   $city = $userInfo->mostSpecificSubdivision->name; if ($city == ‘Alicante’ || 
   $city == ‘Murcia’ || $city == ‘Valencia’) { remove_action( ‘woocommerce_after_shop_loop_item’,‘
   woocommerce_template_loop_add_to_cart’, 20 ); remove_action( ‘woocommerce_single_product_summary’,‘
   woocommerce_template_single_price’, 10 ); remove_action( ‘woocommerce_single_product_summary’,‘
   woocommerce_template_single_add_to_cart’, 30 ); remove_action( ‘woocommerce_after_shop_loop_item_title’,‘
   woocommerce_template_loop_price’, 10 ); add_action( ‘woocommerce_single_product_summary’,‘
   nuevo’, 31 ); add_action( ‘woocommerce_after_shop_loop_item’, ‘nuevo’, 11 ); }}
 * function nuevo() {
    global $product; $product_type = $product->product_type; 
   switch ( $product_type ) { case ‘simple’: echo ‘[Consultar](http://tienda.inopol.es/informacion/)
   <style>.woocommerce .button { display: none;}</style>’; break; case ‘variable’:
   echo ‘[Consultar](http://tienda.inopol.es/informacion/)‘; break; default: echo‘
   [Consultar](http://tienda.inopol.es/informacion/)‘; } }

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘problems and more problems!’ is closed to new replies.

 * ![](https://ps.w.org/geoip-detect/assets/icon-256x256.jpg?rev=978998)
 * [Geolocation IP Detection](https://wordpress.org/plugins/geoip-detect/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/geoip-detect/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/geoip-detect/)
 * [Active Topics](https://wordpress.org/support/plugin/geoip-detect/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geoip-detect/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geoip-detect/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [jhonatanll](https://wordpress.org/support/users/jhonatanll/)
 * Last activity: [8 years, 3 months ago](https://wordpress.org/support/topic/problems-and-more-problems-2/#post-9978889)
 * Status: resolved