SERIOUS HELP NEEDED removing “don’t show this again” checkbox from newsletter {magento-2}

The question:

i want to remove the checkbox of “dont show this popup again” and do some change to display popup only one time.
currently, it is displaying every time i refresh the page to jump to another page.
here is the screen shot :
removing that checkbox from newsletter and restricting it to appear only one time

and here is the code from

public_html/app/code/CleverSoft/Newsletter/view/frontend/templates/newsletter/

code:

<div class="block-content">
            <label class="subcriper_label checkbox-filter">
                <input type="checkbox">
                <span class="checkbox-material"><span class="check"></span></span>
                <?php echo __('Don't show this popup again'); ?>
            </label>
        </div>
        <script>
            require([
                "jquery",
                'Magento_Ui/js/modal/modal',

                "jquery/jquery.cookie"
            ], function(  $, modal  ) {
                //<![CDATA[
                $(function () {
                    function setCookie(cname, cvalue, exdays) {
                        var d = new Date();
                        d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
                        var expires = "expires="+d.toUTCString();
                        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
                    }
                    function getCookie(cname) {
                        var name = cname + "=";
                        var ca = document.cookie.split(';');
                        for(var i = 0; i < ca.length; i++) {
                            var c = ca[i];
                            while (c.charAt(0) == ' ') {
                                c = c.substring(1);
                            }
                            if (c.indexOf(name) == 0) {
                                return c.substring(name.length, c.length);
                            }
                        }
                        return null;
                    }

                    var subscribeFlag = getCookie('cleverNewsletterSubscribeFlag');

                    $('#zoo_newsletter .subcriper_label input').on('click', function () {
                        if ($(this).parent().find('input:checked').length > 0) {
                            setCookie('cleverNewsletterSubscribe','true',2147483647);
                        } else {
                            setCookie('cleverNewsletterSubscribe',null,1);
                        }
                    });

                    $('#zoo_newsletter button.btn-novetty').on('click', function () {
                        var button = $(this);
                        setTimeout(function () {
                            if (!button.parent().find('input#zoo-newsletter').hasClass('validation-failed')) {
                                setCookie('cleverNewsletterSubscribeFlag','true',2147483647);
                            }
                        }, 500);
                    });

                    if (!(subscribeFlag) && !getCookie('cleverNewsletterSubscribe')) {
                        var options = {
                            type: 'popup',
                            modalClass: 'zoo-newsletter-popup',
                            responsive: true
                        };
                        var popup = modal(options, $('#zoo_newsletter'));
                        setTimeout(function(){
                            $('#zoo_newsletter').modal('openModal');
                        },<?php echo $delay; ?>);

                    }
                });
                //]]>
            })

        </script>
    </div>

can someone please tell me how can i create cookie to restrict it to display only one time.
its poping up again and again after every refresh and on everypage.
please guide me what cookie code should i use.
i dont know much about using javascript.
need serious help here please dear seniors help me.

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

I hope below code help you…

<div id="singup_popup_overlay" class="newsletter_popup">
<div id="singup_popup" class="newsletter_popup_title">
    <div class="newsletter_img">
        <img src="<?php echo $block->getViewFileUrl('images/new.png')?>"/>
    </div>
    <div class="newsletter_popup_content">
        <div id="signup_close" class="close_button">
            <i class="fa fa-times" aria-hidden="true"></i>
        </div>
        <div class="title">
            <h3><?php echo __('Newsletter')?></h3>
        </div>
        <p><?php echo __('Sign Up for exclusive updates, new arrivals and insider-only discounts')?></p>
        <?php echo $block->getLayout()->createBlock("MagentoNewsletterBlockSubscribe")->setTemplate('Magento_Newsletter::subscribe.phtml')->toHtml(); ?>
    </div>
</div>
<script type="text/javascript">
require(['jquery'],function(){

    function setCookie(cname,cvalue,exdays) {
        var d = new Date();
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
        var expires = "expires=" + d.toGMTString();
        document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
    }

    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function checkCookie(cname) {
        var user=getCookie(cname);
        if (user != "") {
            return "1";
        } else {
            return "0";
        }
    }

    jQuery(document).ready(function () {
        var popupShow = checkCookie("signup_popup_show");
        if(popupShow != "1") {
            jQuery('body').addClass("no-scroll");
            jQuery('#singup_popup_overlay').fadeIn('fast');
            jQuery('#singup_popup').fadeIn('fast');
        }
    });
    jQuery('#signup_close').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        jQuery('body').removeClass("no-scroll");
        jQuery('#singup_popup_overlay').fadeOut('fast');
        jQuery('#singup_popup').fadeOut('fast');

        setCookie("signup_popup_show", 1, 1);
    });
    jQuery('#singup_popup_overlay').click(function () {
        jQuery('body').removeClass("no-scroll");
        jQuery(this).fadeOut('fast');
        jQuery('#singup_popup').fadeOut('fast');
    });
});


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment