0

I have a plugin which help me to book events. I have integrated a mail scheduler for reminder emails & feedback emails.

On confirmed booking emails are scheduled for reminder as well as feedback. I have both options to define it globally as well as individually to each event. This class is adding actions for the scheduled emails.

class WooEvent_Reminder_Email {
    public function __construct()
    {
        add_filter( 'exc_mb_meta_boxes', array($this,'email_reminder_metadata') );
        // Schedule the event when the order is completed.
        add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email' ), 10, 1 );
        add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email_fb' ), 11, 1 );
        // Trigger the email.
        add_action( 'wooevent_email_reminder', array( &$this, 'send_mail' ),10,4 );
        add_action( 'wooevent_email_reminder_2', array( $this, 'send_mail' ),10,4 );
        add_action( 'wooevent_email_reminder_3', array( $this, 'send_mail' ),10,4 );
        add_action( 'wooevent_email_reminder_feedback', array( $this, 'send_mail_fb' ),10,3);
        // send email to attendee 
        add_action( 'we_send_email_reminder', array( &$this, 'send_mail_attendee' ),10,1 );
    }

Now, due to some reasons the event is not happening and I have created one more category for products "event-deactivated". If this category, I want to disable the event as well as want to remove all further email actions (i.e. no more notifications to the customer). For this objective, I am running this code:

add_filter('woocommerce_is_purchasable', 'nms3_catalog_mode_on_for_product', 10, 2 );

function nms3_catalog_mode_on_for_product( $is_purchasable, $product ) {
    global $WooEvent_Reminder_Email;
    if( has_term( 'seminar-deaktiviert', 'product_cat', $product->get_id() ) ) { 
    // you can set multiple conditions here
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
    // Trigger the email.
    remove_action( 'woocommerce_order_status_completed', array( $WooEvent_Reminder_Email, 'remind_email' ), 10, 1 );
    remove_action( 'woocommerce_order_status_completed', array( $WooEvent_Reminder_Email, 'remind_email_fb' ), 11, 1 );
    remove_action( 'wooevent_email_reminder', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
    remove_action( 'wooevent_email_reminder_2', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
    remove_action( 'wooevent_email_reminder_3', array( $WooEvent_Reminder_Email, 'send_mail' ), 10, 4 );
    remove_action( 'wooevent_email_reminder_feedback', array( $WooEvent_Reminder_Email, 'send_mail_fb' ), 10, 1 );
    // send email to attendee 
    remove_action( 'we_send_email_reminder', array( &$WooEvent_Reminder_Email, 'send_mail_attendee' ),10,1 );
    return false;
    }

    return $is_purchasable;
}

With which action/filter, I should use the above or any modifications.

I am able to disabled the event on the basis of category, but already scheduled email are still queued up.

Any suggestions or help will be appreciated. Thanks

dig99
  • 116
  • 1
  • 6
  • Try to set a higher priority for the removing action function! Try 99 or something like this. – Mr. Jo Oct 18 '21 at 09:03
  • @Mr.Jo Thanks for taking out your time. I think the emails are scheduled at the time of order(completed order). How to remove those scheduled emails when I am applying the deactivation later by assigning a category. – dig99 Oct 18 '21 at 09:50
  • Could be possible that you are removing them too late as well yep – Mr. Jo Oct 18 '21 at 10:07
  • 1
    First and foremost. If you use a plugin, it is always useful to include a link to it in your question. Since there are many plugins with similar names, or even better, a link to the file you copied the existing code from. If you apply a remove_action, try it first in general to see if it gives a result without further conditions, it makes little sense to have a series of conditions if it does not yield the desired result without conditions. The way you are currently applying it, seems to me to be a totally wrong approach – 7uc1f3r Oct 18 '21 at 12:13
  • @7uc1f3r Class-reference: https://pastebin.com/S6yf6eHh May be my approach is wrong, feel free to suggest. This plugin is not from Wordpress repository, (src: https://exthemes.net/wooevents/doc/). remove action is working, but already scheduled email for existing order need to be tackled. How to remove them from scheduler... here I stuck – dig99 Oct 18 '21 at 13:04
  • For answers to questions like this, I'd like to have access to the full code so I can test my answer before posting. Since this is a paying plugin, and the chance that other members on SO here use the same plugin is rather small, I believe it is better that you contact the plugin developer(s). – 7uc1f3r Oct 18 '21 at 13:23
  • Thanks @7uc1f3r let's make it general, how to remove scheduled email which are generated on completed order, based on a certain condition(I have used the term 'Event-deactivated'). – dig99 Oct 18 '21 at 13:29
  • In short: As you can see there are 2 add_action used: `add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email' ), 10, 1 );` & `add_action( 'woocommerce_order_status_completed', array( $this, 'remind_email_fb' ), 11, 1 );`. In those callback functions the email is scheduled via wp_schedule_single_event, so you should apply a remove_action to those hooks, and then you can add your own callback functions via a custom add_action, which will then schedule emails based on your conditions, as opposed to the standard behavior. However, this requires the necessary knowledge. – 7uc1f3r Oct 18 '21 at 13:42
  • @7uc1f3r Thanks for the details, can I use `remove_all_filters( $tag, $priority );`, As on deactivation I would like to remove all hooks related to that order. can you provide any link/reference to use it in case of emails? – dig99 Oct 19 '21 at 09:43

0 Answers0