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;
}
} );