How To Show Cookie Popup in Magento 2

Magento 2 How To Show Cookie Popup

Today, we will see how to show cookie popup in Magento2 on website.
When user open or access first time website, its ask to accept terms policy.
This model popup show until visitors accept or close.

Apply below bootstrap and jquery code to show popup-

HTML code

<div id="cookie-popup-window" style="display:none;">
  <p>Accept cookies policy</p>

<script type="text/javascript">
require([ 'jquery','Magento_Ui/js/modal/modal','mage/cookies'], function($,modal) {

   var options = {
        type: 'popup',
        responsive: true,
        innerScroll: true,
        title: '',
        modalClass: 'custom-window-block',
        buttons: [{
            text: $.mage.__('Continue'),
            class: '',
            click: function () {

  var popup = modal(options, $('#cookie-popup-window'));
  if ($.cookie('popuplogintext') != 'open') {
      $.cookie('popuplogintext', 'open', { path: '/' });//Set the cookies

Related blog – Custom attribute not saving in Magento2

Like us on Facebook and Linkedin for more updates.

Back To Top