Site logo

[Support request] Show block element on in certain countries

Home Forums Support [Support request] Show block element on in certain countries

Home Forums Support Show block element on in certain countries

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #2436156
    Max

    Hi there!

    I’ve a block element that I want to add to a few pages, but only to visitors from a specific country.

    Would this be possible with a setting or some kind of php snippet?

    Thanks!

    #2436196
    Max

    I’ve tried this, but that didn’t work:

    add_filter( 'generate_element_display', function( $display, $element_id ) {
        global $post;
    
        if ( 34988 === $element_id && ( is_page() && $post->post_parent == '34994' ) ) {
            if (geoip_country_code_by_name($_SERVER['REMOTE_ADDR']) == 'DE') {
                $display = true;
            }
        }
    
        return $display;
    }, 10, 2 );

    Id of the element = 34988
    Page I want to show it on = 34994

    #2436366
    Ying
    Staff
    Customer Support

    Hi Max,

    I’m not aware of an easy way to get the user’s geolocation.

    It will require custom development or a plugin.

    #2436796
    Max

    Too bad! I thought it would be possible to make some kind of IF statement to check the country.

    #2437756
    Ying
    Staff
    Customer Support

    Woocommerce has that function built-in, if you are using Woocommerce it might be worth a try to contact their support.

    Otherwise, a plugin or custom development will be required.

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.