• Resolved jhonatanll

    (@jhonatanll)


    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<style>.woocommerce .button { display: none;}</style>’;
    break;
    case ‘variable’:
    echo ‘Consultar‘;
    break;
    default:
    echo ‘Consultar‘;
    }
    }

    add_action(‘init’, ‘ven’);

    and thank you very much for the plugin!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Benjamin Pick

    (@benjamin4)

    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
    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

    Thread Starter jhonatanll

    (@jhonatanll)

    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!

    Plugin Author Benjamin Pick

    (@benjamin4)

    (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

    (@jhonatanll)

    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<style>.woocommerce .button { display: none;}</style>’;
    break;
    case ‘variable’:
    echo ‘Consultar‘;
    break;
    default:
    echo ‘Consultar‘;
    }
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘problems and more problems!’ is closed to new replies.