1
 html += this + '<div class="dropD"><strong>i</strong></div>' +
                        '<div class="rect" id="futureDates">' + table +
                        '</div>' +

I have this code within .js file but I want to run this div only when customer is logged in. This div executes in frontend while viewing products PLease suggest some ways.

5

Plese check with below code to check customer is logged in or not and add your html code..

if you want to add below code in phtml file than replace 'define' to require

    define(['jquery','Magento_Customer/js/model/customer'], function ($,customer) {
        if (customer.isLoggedIn()) {
            alert('loggedin')
        } else{
            alert('loggedout')
        }
});
  • it didnot work. – Naiwrita09 Aug 29 at 5:57
  • let me check again... – Anas Mansuri Aug 29 at 6:13
  • please check, i update my answer. its working my side – Anas Mansuri Aug 29 at 6:38
  • 1
    Uncaught TypeError: customer.get is not a function – Hafiz Arslan Aug 29 at 13:51
  • 1
    Thank u it's working on checkout page – Hafiz Arslan Aug 30 at 10:22

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.