• Resolved Eric De Kock

    (@ericdk)


    Hi there

    I’m busy developing our new website with the elementor page builder. I have added a custom control which adds a custom class to each section element.

    The reason for this is that we display certain products based on the specific state. I detect users according to their ip and based on their state I can hide the content not relevant to them.

    What I would like to do before the items render on the pages I would like to only render the state-specific sections to make the page lighter for the user.

    Please let me know if this makes sense and if you need any more details from me.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Eric De Kock

    (@ericdk)

    Just to give you an idea what I have done thus far.

    Below is the control I have created which will add the class show-‘state’ to the section.

    In the section action you will notice that I’m checking each section’s setting and comparing the setting with the current active user state.

    My last step would be to print the element if the user state and the section state are equel. How would I print only that element.

    add_action( ‘elementor/element/before_section_start’, function( $element, $section_id, $args ) {
    /** @var \Elementor\Element_Base $element */
    if ( ‘section’ === $element->get_name() && ‘section_background’ === $section_id ) {

    $element->start_controls_section(
    ‘states’, [
    ‘tab’ => \Elementor\Controls_Manager::TAB_STYLE,
    ‘label’ => __( ‘States’, ‘state-select’ ),
    ]
    );

    $element->add_control(
    ‘custom_control’, [
    ‘type’ => \Elementor\Controls_Manager::SELECT,
    ‘label’ => __( ‘Choose your state’, ‘state-select’ ),
    ‘default’ => ‘sa’,
    ‘options’ => array( ‘all’ => ‘ALL’, ‘sa’ => ‘SA’, ‘wa’ => ‘WA’, ‘nsw’ => ‘NSW’, ‘vic’ => ‘VIC’, ‘qld’ => ‘QLD’, ‘act’ => ‘ACT’ ),
    ‘prefix_class’ => ‘show-‘,
    ‘label_block’ => true,
    ]
    );
    $element->end_controls_section();
    }
    }, 10, 3 );

    add_action( ‘elementor/frontend/element/before_render’, function ( \Elementor\Element_Base $element ) {
    if ( ‘section’ === $element->get_name() ) {
    //$geoip2_state = strtolower( get_geoip2_country_state( get_visitor_IP() ) );
    $activestate = $element->get_settings( ‘custom_control’ );

    if ( $activestate == $_COOKIE[‘userState’] ):
    echo ‘eq: ‘ . $activestate;
    //$element->print_element();

    else:
    //$element->print_element();
    echo ‘not eq: ‘ . $activestate;
    endif;
    }
    } );

    This is beyond the scope of this forum

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

The topic ‘Hide section elements based on GEO Content’ is closed to new replies.