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.


1 Answer 1


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()) {
        } else{
  • it didnot work.
    – Naiwrita09
    Aug 29, 2019 at 5:57
  • let me check again... Aug 29, 2019 at 6:13
  • please check, i update my answer. its working my side Aug 29, 2019 at 6:38
  • 1
    Uncaught TypeError: customer.get is not a function Aug 29, 2019 at 13:51
  • 1
    Thank u it's working on checkout page Aug 30, 2019 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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