skip to Main Content

At: www.TattiniBoots.com/Shop you see that there is a red store notice at the top.

Is there a way to hide this if the current viewer has a United States IP address?

2

Answers


  1. In the Woocommerce admin, go to Settings > General. There will be an option under “General options” for “Default customer location”. Set this value to “Geolocate”.

    In your theme or plugin, you can use the function wc_get_customer_default_location(), which returns an array of containing country and state. Simply check the value of country in the array to see if it matches ‘US’ and modify your code as needed.

    Login or Signup to reply.
  2. Add the follows code snippet to do so –

    add_filter( 'woocommerce_demo_store', 'modify_woocommerce_demo_store', 99 );
    
    function modify_woocommerce_demo_store( $notice_html ) {
        // Get geolocated user geo data.
        $user_geodata = WC_Geolocation::geolocate_ip();
        if( $user_geodata && !isset( $user_geodata['country'] ) ) return $notice_html;
        if( $user_geodata['country'] == 'US' ) return '';
        return $notice_html;
    }
    

    Codes goes to your active theme’s functions.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search