• Resolved malorkan

    (@malorkan)


    is it possible to execute the shortcode only under the condition that a cookie is set beforehand?
    i use elementor and have tried back and forth to put it into an html or shortcode element using an if condition like this one

    <script>
    document.addEventListener('DOMContentLoaded', function() {
        // überprüfe hier deine Bedingung
        if (document.cookie.indexOf('cmplz_preferences=allow') !== -1) {
            // Füge den Shortcode-Inhalt in das DOM ein
            var shortcodeContainer = document.getElementById('mwai_chatbot_v2');
            if (shortcodeContainer) {
                shortcodeContainer.innerHTML = [mwai_chatbot_v2];
            }
        }
    });
    </script>
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Val Meow

    (@valwa)

    Hey @malorkan ! ??

    It might be easier to check for cookies and create a shortcode through the backend, as they are interpreted by WordPress. You could try something like this. ??

    function custom_cookie_chatbot_shortcode_callback($atts) {
        // Check if the cookie is set
        if (isset($_COOKIE['cmplz_preferences'])) {
            // Render the mwai_chatbot_v2 shortcode content here
            return do_shortcode('[mwai_chatbot_v2]');
        } else {
            // Optionally, you can provide a message or alternative content
            return 'Cookie not set, chatbot shortcode not rendered';
        }
    }
    add_shortcode('cookie_mwai_chatbot_v2', 'custom_cookie_chatbot_shortcode_callback');
    
    Thread Starter malorkan

    (@malorkan)

    thanks for your quick reply. i had tried that but unfortunately the approach did not work. can you describe how you can activate the shortcode through the backend? that i only activate the chatbot under the cookie condition on individual pages

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcode under Cookie condis’ is closed to new replies.