0

we are setting up a autoresponder to send to the email of the customer who's order status is changed to completed (were using woocommerce and wordpress and mailster for the autoresponder). The autoresponder and action hook is working properly. The hook triggers the autoresponder to send the email but we can't seem to figure out the code to add so the autoresponder will send the email only to the email of the customer who's order is changed to completed.

We've tried playing with the receivers list provided by the plugin but we can't seem to find the option to put the required condition.

Here's the code we use for the trigger:

function trigger_autoresponder($order_id) {     
    do_action( 'my_custom_hook' );    
}

// add the action 
add_action( 'woocommerce_order_status_completed', 'trigger_autoresponder', 10, 1 );

We expected the autoresponder to send the email to customer's email who triggered the hook only. Your help is much appreciated. Thank you so much in advance.

Aaron Tan
  • 13
  • 2

1 Answers1

0

This will do it. I posted an edit on your other question.

function trigger_autoresponder($order_id) {  
    $subscriber_id = mailster_get_current_user_id();
    do_action( 'my_custom_hook', $subscriber_id );    
}

// add the action 
add_action( 'woocommerce_order_status_completed', 'trigger_autoresponder', 10, 1 );
KGreene
  • 790
  • 7
  • 11
  • Good day sir, we tried the code and unfortunately it's still sending to all subscribers. We're trying to send it only to the billing email address of the customer who triggered the autoresponder. We tried following this tutorial as well and still cant get it to send to the specific email only. [https://stackoverflow.com/questions/47648386/sending-email-to-customer-on-cancelled-order-in-woocommerce?rq=1] – Aaron Tan Nov 04 '19 at 17:27
  • If they created an order, their email will be listed in the default list in pending status. The autoresponder is triggered when order is completed so it should exist in mailster list. – Aaron Tan Nov 04 '19 at 20:59
  • That is true if you only have 1 list. If you have multiple you need to select which list they get added to. I'm just checking off boxes to make sure. Do might need to look up the mailster subscriber ID based on the billing email rather than the current user. – KGreene Nov 04 '19 at 21:09
  • the "List doesn't matter" for the receivers is checked so it should use any list to check the current user. the code you provided should work. I don't understand why it's sending it to everyone in the list. Do you have anymore ideas I can test? I've tried different methods including woocommerce billing_email and $subscriber and still can't get it done properly. – Aaron Tan Nov 04 '19 at 22:50
  • I think its not getting any value for the subscriber_id. Do you have access to the error_logs? You can error _log($subscriber_id); and see if its valid. If its blank it will send to all list members. – KGreene Nov 04 '19 at 23:07