Skip to content

Instantly share code, notes, and snippets.

@vanbo
Last active May 10, 2021 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanbo/2c99dbe4b6f6f194002f3cc6ead6da18 to your computer and use it in GitHub Desktop.
Save vanbo/2c99dbe4b6f6f194002f3cc6ead6da18 to your computer and use it in GitHub Desktop.
wc paysafe send payment complete emails to the admin as well
add_action( 'init', 'vanbodevelops_add_email_actions' );
function vanbodevelops_add_email_actions() {
// Triggers for this email.
add_action( 'woocommerce_order_status_cancelled_to_processing_notification', 'send_order_emails', 11, 2 );
add_action( 'woocommerce_order_status_failed_to_processing_notification', 'send_order_emails', 11, 2 );
add_action( 'woocommerce_order_status_on-hold_to_processing_notification', 'send_order_emails', 11, 2 );
add_action( 'woocommerce_order_status_pending_to_processing_notification', 'send_order_emails', 11, 2 );
}
/**
* Sends the processing email to the admin
*
* @param $order_id
* @param bool $order
*/
function send_order_emails( $order_id, $order = false ) {
if ( $order_id && ! is_a( $order, 'WC_Order' ) ) {
$order = wc_get_order( $order_id );
}
$emails = WC()->mailer();
/**
* @var \WC_Email_Customer_Processing_Order $processing_email
*/
$processing_email = $emails->emails['WC_Email_Customer_Processing_Order'];
add_filter( 'woocommerce_email_recipient_customer_processing_order', 'vanbodevelops_admin_email', 10, 3 );
add_filter( 'woocommerce_email_subject_customer_processing_order', 'vanbodevelops_admin_email_subject', 10, 3 );
$processing_email->trigger( $order_id, $order );
remove_filter( 'woocommerce_email_recipient_customer_processing_order', 'vanbodevelops_admin_email', 10 );
remove_filter( 'woocommerce_email_subject_customer_processing_order', 'vanbodevelops_admin_email_subject', 10 );
}
/**
* Returns the admin email address
*
* @param $recipient_email
* @param $order
* @param $email
*
* @return string
*/
function vanbodevelops_admin_email( $recipient_email, $order, $email ) {
// Enter your admin email here
// For multiple emails separate them with a comma (,)
$admin_email = 'please_enter_your_email@domain.com';
// $admin_email = get_option( 'admin_email' ); // Returns the admin email in WP
return $admin_email;
}
/**
* @param $subject
* @param \WC_Order $order
* @param $email
*
* @return string
*/
function vanbodevelops_admin_email_subject( $subject, $order, $email ) {
return 'Payment was successful for order #' . $order->get_order_number();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment