Reputation: 811
I'm trying to send a custom email when a post is published using the Woocommerce email template.
I have included the template and class which Woocommerce loads using the woocommerce_email_classes
and have also registered the custom action send_entry_list
in the woocommerce_email_actions
filter.
do_action('send_entry_list', $competition_id, $entry_list_url);
When adding add_action
to this within the class-entry-list-email.php
which triggers the email, it's not printing out 'triggered
' in the debug.log file.
Does anyone know why this isn't firing?
public function __construct() {
add_action( 'send_entry_list', array( $this, 'trigger' ) );
}
public function trigger( $competition_id, $entry_list_url ) {
error_log(print_r('triggered', true));
}
add_filter( 'woocommerce_email_classes', array($this, 'add_draw_number_email'));
function add_draw_number_email( $email_classes ) {
// include our custom email class
require( 'includes/class-entry-list-email.php' );
// add the email class to the list of email classes that WooCommerce loads
$email_classes['Entry_List_Email'] = new Entry_List_Email();
return $email_classes;
}
add_filter( 'woocommerce_email_actions', array($this, 'crwc_register_custom_order_status_action'));
function crwc_register_custom_order_status_action( $actions ) {
$actions[] = 'send_entry_list';
return $actions;
}
Upvotes: 0
Views: 1319
Reputation: 2386
Actually, you are missing _notification
in the add_action
hook. In WooCommerce email, you need to add _notification
in the tag
name of do_action
.
In your case, you are using send_entry_list
in both do_action
and add_action
whereas in add_action
you just need to append _notification
in the tag
name so hook name becomes send_entry_list_notification
.
To make this easy for you just do the following change.
Replace this line:
add_action( 'send_entry_list', array( $this, 'trigger' ) );
with this:
add_action( 'send_entry_list_notification', array( $this, 'trigger' ), 10, 2 );
Hope, it works for you.
Upvotes: 4
Reputation: 649
Change hook as below and try,
add_action( 'send_entry_list', array( $this, 'trigger' ), 10, 2 );
Upvotes: 0