Subscription after expired mail sent many time on the same day

Member's membership is expired. But they are getting a Subscription - After Expired email twice in a same day.
The email is sent out every 6 hours. I like the email to be sent once. If it is a default behavior how can I set it so it gets sent only once.

  • Adam Czajczyk
    • Support Gorilla

    Hello Jing

    I hope you're well today!

    The e-mail should be sent once but both membership expiration and e-mail sending processes are triggered on a schedule by cron. The "regularity" of these notifications suggest that for some reason an e-mail queue might not be cleared up properly or something is triggering the same e-mail again and again.

    However, we'll need our developers' help on this so I have already forwarded the case to them and am awaiting their response. They'll check your site and we'll update you here as soon as we got feedback from them.

    Kind regards,
    Adam

  • Adam Czajczyk
    • Support Gorilla

    Hello Jing

    It might take our developers a bit longer to respond than it usually takes us here on support forum as they are dealing with a lot of complex stuff on daily basis so I'd appreciate some patience on this.

    I have just messaged them again asking them to get back to us with a status of this as soon as possible so either I or one of my colleagues will update you here once we only get to know more.

    Kind regards,
    Adam

  • Jing
    • Recruit

    Thanks,
    but it's take too long time.
    still it will take how much time..?
    you know this is a very urgent issue ..?
    if you are working on that change can you please keep post me update.
    and if is still take a time so let me know i will find another way..
    Thanks.

  • Panos
    • SLS

    Hi Jing ,

    Sorry for delay!

    I have been trying to replicate this issue in my test sites but with no luck. So I would like to test this on your site to see what I have been missing. I see you have deactivated that email repsponse, so I have activated it again in order to see if it sends multiple emails indeed.

    I tried adding :
    define( "MS_LOG_EMAILS", true );
    in the wp-cofig.php file in order to log the emails that are sent, but I wasn't allowed to update file. So I created a new mu-plugin file wp-content/mu-plugins/ms-log-emails.php where I added that define.

    With that define it should log the Membership emails sent to members and are listed in:
    yoursite.com/wp-admin/admin.php?page=membership2-help&tab=emails

    Since you have monthly memberships only, I tried by forcing the expiration date manually but no luck with the email. I have created a new daily membership and a subscription using it which I would like to let it expire on it's own. I activated the Stripe Single payment to make the test purchase and deactivated it again. That test membership still exists on your site, but I have filtered it so it doesn't show up in front memberships list. That membership is called Test Daily Membership.

    If you want you can also install a plugin for loging emails like WP Mail Logging which also lists all emails sent.

    This way we can see if indeed those Expired messages are sent multiple times and find out what is causing this, else we can provide a workaround.

    Kind regards!

  • Jing
    • Recruit

    Thanks.

    sorry, but i do not understand what you did and what you asked..?
    i am sure there is a problem, and still i have not found any solution,
    and this is a second time my user got the multiple email at the same day .
    so i accepting from you solve this issue immediately please

    Thanks

  • Jing
    • Recruit

    HI i have checked in a email history log. and i found you have registered with a test email with a test membership . and see this screenshot
    you have also got the two email on same day and same email.
    is this make sense..?
    or am i doing anything wrong...
    in short user get the many email for reminder
    so please check and please solve that issue

    Thanks

  • Adam Czajczyk
    • Support Gorilla

    Hi Jing

    I took a quick look at the mail logs on the site to follow up on what Panos asked for in his last post and I can confirm that what you found is right - there seem to be those multiple mails reflected in the logs too. I've also messaged Panos about that, just in case he missed notification of your post, so he'll be investigating that further and will get back to you here as soon as possible.

    Kind regards,
    Adam

  • Panos
    • SLS

    Hi Jing ,

    I'm really sorry for not replying here sooner.

    I could replicate that from my side also after many tries. So there will be a fix for this shortly. For the time being, I have added this mu-plugin:
    https://gist.github.com/wpmudev-sls/6b3ab59769f105c9577d70e04e48aa38
    on your site.

    It should stop sending multiple email duplicates. Would you mind if I add :
    define( "MS_LOG_EMAILS", true );
    again, so we can continue monitor this on your site too?

    Kind regards!

  • Panos
    • SLS

    Hi Jing ,

    Since I'm not sure what you mean, could you please confirm if it is OK if I added that define on your site?

    From your reply I understand that you don't want me to add it, so I just want to double check :slight_smile:

    If you are certain that this issue has stopped then there is no need to add that.

    Kind regards!

  • Panos
    • SLS

    Hi Jing !

    Sorry to hear you are still having this issue! Thanks for informing us via our chat!

    I would like to apologize as I intended to email you asking more information about those emails, but the email wasn't sent.

    About that issue, I could replicate that on my test site and I made a patch that did work on my test sites. For some reason that patch is not working on your site. We are currently looking into it and will update you shortly!

    Kind regards!

  • Panos
    • SLS

    Hi Jing !

    I would like to know if you added the mu-plugin mentioned above:
    https://gist.github.com/wpmudev-sls/6b3ab59769f105c9577d70e04e48aa38

    If not, download the zip from there, unzip and upload file class-ms-model-relationship.php to your wp-content/mu-plugins folder

    It requires one more step though. In order to make this mu-plugin to work, you need to modify file membership/app/model/class-ms-model-relationship.php. You need to add the following snippet :

    do_action(
    			'ms_model_relationship_check_membership_status_before',
    			$this
    		);

    right after:
    public function check_membership_status() {
    should be around line 2882

    If you prefer I could apply those changes on your live site, however I would need admin and ftp access. You have already sent in admin access, you can send ftp credentials privately through our contact form: https://premium.wpmudev.org/contact/#i-have-a-different-question

    Send in:Subject: "Attn: Panos Lyrakis"

    - FTP credentials
    host
    username
    password
    (and port if required)

    - link back to this thread for reference

    Kind regards!

  • Jing
    • Recruit

    please check the email

    and please update me asap , i am waiting for your response .
    also please let me know how can i check a this without send the email to any customers ..?
    how i can check your patch code is working or not..?
    is there any way to do this..?
    Thanks..

  • Panos
    • SLS

    Hi Jing !

    I have applied patch on your site. In order to test:

    1. Create a test user and subscribe him to a membership. This can be done via admin.
    2. Set the expiration date of the membership to the past, but this needs to be exactly 3 days before current date. 2 days the message delay, plus one day the default grace period = 3 days. So if current day is 26 Feb, you need to set expiration date to 23 Feb.
    3. From admin > Membership 2 > Settings at the footer there is a link to run status check cron and another link to run cron for emails. First click on the Check Membership Status change and then refresh the page. There should be a few emails to be sent for the test member. One of them should be for expiration. You can click to send those. Then repeat that step, click on Check Membership Status change once more and refresh. It shouldn't have the same pending emails (eg for expiration).

    I would suggest to test that on your staging site. If you want to do those tests on your live site you can add the following snippet :

    add_action( 'wp_mail', function( $args ){
    	$args['to'] = 'test@test.com';
    	return $args;
    } );
    in a mu-plugin, or you can use a plugin like:
    https://wordpress.org/plugins/disable-emails/

    Those should be removed immediately after testing though.

    Kind regards!

  • Adam Czajczyk
    • Support Gorilla

    Hello Jing

    Thanks for confirmation, I'm glad to hear that :slight_smile:

    I believe that the "patch" added by Panos is the code snippet that he mentioned in this post above:

    https://premium.wpmudev.org/forums/topic/subscription-after-expired-mail-sent-many-time-on-the-same-day#post-1379389

    If so, that would mean that you can safely update the plugin but please hold on a bit. I have messaged Panos directly asking him to get back to us and confirm so let's first get confirmation from him.

    Best regards,
    Adam

  • Panos
    • SLS

    Hi Jing ,

    In the wp-content/mu-plugins folder I added this mu-plugin:
    https://gist.github.com/wpmudev-sls/6b3ab59769f105c9577d70e04e48aa38

    Then in file
    wp-content/plugins/membership/app/model/class-ms-model-relationship.php
    right after line :
    public function check_membership_status() {

    I added this piece:

    do_action(
    	'ms_model_relationship_check_membership_status_before',
    	$this
    );

    This should be already included in next release but you will still need the mu-plugin. For current version you need both.

    Please let me know if I wasn't clear here.

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.