Snippets

Visser Labs Generate e-mail on failed Scheduled Export

Created by Michael Visser

File functions.php Added

  • Ignore whitespace
  • Hide word diff
+<?php
+function custom_woo_ce_failed_scheduled_export( $scheduled_export, $error = '' ) {
+
+	// Send an e-mail on failed Scheduled Exports
+	$to = 'store-owner@your-domain.com';
+
+	$subject = sprintf( 'Scheduled Export %s failed to complete', get_the_title( $scheduled_export ) );
+	$message = sprintf( 'Scheduled Export %s (Post ID: #%d) failed to complete and returned the following error: %s', get_the_title( $scheduled_export ), $scheduled_export, $error );
+
+	// Send the mail using WooCommerce mailer
+	if( function_exists( 'woocommerce_mail' ) ) {
+		woocommerce_mail( $to, $subject, $message );
+	} else {
+		// Default to wp_mail()
+		add_filter( 'wp_mail_content_type', 'woo_ce_set_html_content_type' );
+		wp_mail( $to, $subject, $message );
+		remove_filter( 'wp_mail_content_type', 'woo_ce_set_html_content_type' );
+	}
+
+}
+add_action( 'woo_ce_failed_scheduled_export', 'custom_woo_ce_failed_scheduled_export', 10, 2 );
+?>
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.