-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added notification emails and basic scheduling logic #648
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work, @peterfabian! Loved how you incorporated the WCS_Scheduler
structure and the date types! Everything seem to be falling into place 🙌
Left some initial thoughts on the structure before I start doing some hands-on testing.
…ubscription settings.
…ttic/woocommerce-subscriptions-core into try/subs-notifications-pf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good @peterfabian. I haven't had a chance to test it today, however I've given it a skim in terms of reviewing the general approach taken.
I left some initial comments. :)
Just a heads up. I noticed in the PR array()
. We have switched to use the shorthand syntax ([]
) however haven't updated all existing uses. Our current approach is to use []
in newer code.
To allow easier batch processing, notifications are updated whenever subscription is updated after the settings changed, if the previous update of the subscription was before the settings changed.
…ttic/woocommerce-subscriptions-core into try/subs-notifications-pf
…tion-expiration.php Co-authored-by: James Allan <[email protected]>
Makes sense, fixed in 78e18e5. |
This is a component reused from WC core, so perhaps I can address it over there. |
I'm happy to go either way, what would be your preference? I tried to blend the files in as I haven't seen other features being separated in the codebase. Since
Similarly,
etc |
…unit tests (#689) * Fix debug tool tests * Test batch processor * Test the emails controller * Fix update time issue on first load * Some polishing * Fix emails controller tests * Fix tests and initial state of DB * More Cleanup; * Bring hosted version of the batch controller and interface * Fix tests to use the new interfaces * Fix the autoloader * Update the processors to use the new interfaces * Fix the main file and enable feature for new installations fix * Cleanup * Cleanup * Revert update-time rename * Use the singleton and update logic to unschedule entities * Improve debug tool copy * Improve tests and docblocks * More relative dates to the batch processor tests * Revert v8 to x.x.x * More test comments
* Updated the emails copy. * Plain emails updated. * Additional fixes. * Renewals aren't always enabled.
Probably a merge mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, @peterfabian! And the issue with the async date changes has been resolved! Left some nit comments mostly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @peterfabian. Sorry for how long it has taken to review this one. 😞
I think next week @mattallan and I need to move quickly to get this approved and merged so you folks can be released back to your normal work load. From there we can work from it as a base.
Our next scheduled release isn't until Nov 19th and so that should be plenty of time to have it running locally and apply fixes to if they come up.
I just skimmed the changes again today, there's a few function block comments etc missing, however that's all minor stuff. I'm going to carve out some time on Monday to really put it through the wringer and hopefully get it approved early.
$this->process_next_batch_for_single_processor( $batch_process ); | ||
}, | ||
10, | ||
2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is only accepting 1 arg isn't it? $batch_process
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe Peter is using a closure here to prevent others from removing that reference by calling "remove_action" for any reason.
cc @peterfabian
Thanks @james-allan 🙌 All your input will be highly appreciated! |
… disabled (#696) * Bulk unschedule actions * Fix unit tests --------- Co-authored-by: Peter Fabian <[email protected]>
* Track the notification global state * Cleanup and add default * Revert auto format fixes
public function handle_woocommerce_debug_tools( array $tools ): array { | ||
|
||
if ( ! WC_Subscriptions_Email_Notifications::notifications_globally_enabled() ) { | ||
$tools['start_add_subscription_notifications'] = array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Just so I understand, this specific tool is added as a "stub" of sorts to the WooCommerce → Status → Tools even though the feature is disabled just for reference? It will always be disabled when the feature isn't enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the idea. Instead of completely hiding this, we keep the UI consistent and use friendly messages.
Initially, before the mass unscheduling, this was (kinda) necessary in case the progressing unscheduling failed. So, essentially, the same handling was maintained after the improvement.
Perhaps the copy could use some improvement? I added some info in this PR if you'd like to take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to merge imo. As I mentioned in my previous comment, this PR is super large and so I've mostly focused on reviewing critical architecture stuff. All the little things I noticed while testing and reviewing can be done in smaller, follow up PRs. I'll fill an issue to note those.
I've tested the following scenarios:
- Enabling the setting schedules jobs for all valid subscriptions.
- Changing the offset updates (cancels and reschedules) all jobs in the background.
- Setting a long pre-event time like 2 months won't schedule any events for subscriptions with an event shorter than 2 months.
- Setting a pre-event time like 7 days and then purchasing a weekly subscription won't schedule a pre-renewal email
- 🔖 Note: I think this is fine given the alternative would be to send an email at the time of purchase and that would be spamming the customer. In this case, the "Thank you for your order" sent for the order includes the next payment date and so it serves the purpose of notifying the customer of the next payment date.
- cancelling an subscriptions schedules the pre-expiration email.
- Fully cancelling a subscription cancels the all pre-notification events.
- Manual vs automatic subscriptions send different emails.
- Renewing early pushes out the scheduled notification.
- Updating the subscription status updates the scheduled notifications.
- Updating the date programmatically updates the scheduled notifications.
- Deleting a subscription date updates the scheduled notifications.
- 🔖 Note: If you delete a trial end date, it doesn't schedule the pre-renewal email. I'll follow up with this later.
- Emails aren't sent while in staging mode.
- Running the actions from the Edit Subscription > Actions dropdown works as expected.
- Noting that the actions listed match the subscription setup. Pre-trial only if in the trial period. Pre-renewal only when there's a next payment date and pre-end if there's a scheduled end date.
- Synced subscriptions work as expected. The pre-renewal email is scheduled x days prior to the sync date.
- Switching 🙈
- Switching to a subscription on a different period updates the events. 👍
First POC that contributes towards #645
Description
This is a WIP to add notifications to Subscriptions Core.
Currently, it
Mostly, it's inspired by code that's already in Subscriptions Core.
Notification Types Added
$subscription->get_date( 'next_payment' )
for automatically renewing subscriptions ($subscription->is_manual()
isfalse
)$subscription->get_date( 'next_payment' )
manual subscriptions ($subscription->is_manual()
istrue
)$subscription->get_date( 'trial_end' )
manual subscriptions$subscription->get_date( 'end' )
manual subscriptionsOpen Questions
Some questions that crossed my mind while implementing this:
WCS_Action_Scheduler
, but it seemed more appropriate to create a new class for notifications (WCS_Action_Scheduler_Customer_Notifications
), otherwise the scheduling logic might be a bit complex. It should be quite easy to change this, though.WCS_Action_Scheduler
that relies entirely on Subscription status and which date is being updated (combining the logic ofget_scheduled_action_hook
,update_status
andupdate_date
methods).Most likely not, as it's a lot of work to schedule/unschedule all of them. If they're disabled, this will create clutter in the db, though. Yes, we decided we will do this.Side Notes For Testing
ControlStructureSpacingSniff.php
(converted last argument to array forExtraSpaceBeforeCloseParenthesis
andExtraSpaceAfterCloseParenthesis
sniffs), otherwisephpcs
was failing. Perhaps there's a better way to solve this, but I didn't want to spend too much time investigating what's going on and what array should be passed where it gets a string. Updatingsquizlabs/php_codesniffer
to 3.10.2 didn't help either.TODO
How to test this PR