Jump to content

Best hook method to use?


Lance O.
 Share

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.

Link to comment
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 7
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...