• Resolved jackkemm

    (@jackkemm)


    Hi there, first of all really appreciate the plugin. Make’s life so easy to integrate Shopify ??

    My issue is trying to add an event listener to the actual product divs ‘.wps-item’. I am using the ‘after.ready’ hook but it seems the items are being reinitialised after this hook. I have also tried ‘items.init’ but have the same issue.

    Can you please guide me on the best way to add an event listener as I can’t seem to work it out with the hooks that are provided.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author andrewmrobbins

    (@andrewmrobbins)

    @jackkemm

    Glad the plugin is providing value to you!

    Unfortunately this is a bug in the current version of the plugin. The DOM items shouldn’t be changing but they do because of the way the state is updated.

    I’ll be fixing this in the upcoming version 3.0.

    In the meantime, the below code should be a workaround. Not ideal, but it should work for now.

    
    wp.hooks.addAction("after.ready", "wpshopify", function (shopState) {
      setTimeout(function() {
         // Attach your event listeners here
      }, 1000);
    });
    

    Let me know if this helps!

    Thread Starter jackkemm

    (@jackkemm)

    Hi Andrew,

    Thanks for that, that’s done the trick for the time being.

    Look forward to seeing what else is to come in version 3 ??

    Stay safe.

    Jack

    Plugin Author andrewmrobbins

    (@andrewmrobbins)

    Glad that works for now!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘JS Hooks – Struggling to add event listeners to .wps-item with ‘after.ready’’ is closed to new replies.