1

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.

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("Magento\Newsletter\Block\Subscribe")->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');
    });
});

  • what did you changed in this ans? – Laiba Feb 27 '18 at 12:47
  • pop up permanently stopped displaying after using this code – Laiba Feb 27 '18 at 12:57
  • can you kindly just tell me one simple code by which i can stop its popup to display again and again? – Laiba Feb 27 '18 at 12:59
  • This is a simple code. My code add "signup_popup_show" cookie in browser for one day. You just add my code in to phtml file. and run it. Once it run it will set cookie. – PG Sutariya Feb 28 '18 at 3:54
  • 1
    See, i'll add it in fiddle for you. jsfiddle.net/pgsutariya/aezctrcf/5 – PG Sutariya Feb 28 '18 at 3:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.