Jump to content
Lance O.

Best hook method to use?

Recommended Posts

I want to create a hook that will:

  1. Check for pages with a specific template ("order").
  2. Check that the page has a datetime field that is more than 30 days old.
  3. Send an email to a specific address.
  4. Change the value of a field to show the email was sent.

What is the best hook method to use? I don't necessarily need this to execute on every page load on the public site, and it can't execute when viewing the specific template ("order"), but it can execute when the "orders" page is viewed on the public site.

Share this post


Link to post
Share on other sites

Sounds like you could use LazyCron here. 

Check your pages how often you want (daily, weekly, each hour), look for those pages and do what ever you want to do with them.

Put things like this in ready.php or create a module:

<?php namespace ProcessWire;

wire()->addHookAfter('LazyCron::every6Hours', function (HookEvent $e) {

    $pagesOlderThirtyDays = $e->pages->findMany("template=order, ... ");

    foreach ($pagesOlderThirtyDays as $potd) {

        // WHATEVER YOU WANT
        
    };

});

 

  • Like 6

Share this post


Link to post
Share on other sites

@wbmnfktr This is perfect, thank you! Thanks for steering me in a better direction.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...