Filter
uncanny-automator-pro
automator_pro_woo_create_and_email_coupon
Filters the email headers when creating and emailing a WooCommerce coupon via the Automator Pro integration.
add_filter( 'automator_pro_woo_create_and_email_coupon', $callback, 10, 2 );
Description
Filters email headers before sending a WooCommerce coupon via Uncanny Automator Pro. Developers can modify headers like 'Bcc' or 'Reply-To', or add new ones, to customize the email delivery process for the "Create and email coupon" action.
Usage
add_filter( 'automator_pro_woo_create_and_email_coupon', 'your_function_name', 10, 2 );
Parameters
-
$headers(mixed) - This parameter contains an array of email headers that will be included in the email sent with the coupon.
-
$this(mixed) - This parameter contains an array of email headers, such as 'Bcc' and 'Reply-To', which can be modified by the filter.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the email headers for the WooCommerce Create and Email Coupon action.
* This example adds a custom header to the email.
*/
add_filter( 'automator_pro_woo_create_and_email_coupon', function( $headers, $action_instance ) {
// Check if the action instance is of the correct type (optional but good practice)
if ( ! is_a( $action_instance, 'Uncanny_Automator_ProIntegrationsWooCommerceActionsWC_CreateAndEmailCoupon' ) ) {
return $headers;
}
// Add a custom header, for example, to track the automation that sent the email.
// In a real scenario, you might dynamically generate this based on the automation's ID or name.
$headers[] = 'X-Automator-Source: UncannyAutomatorProWooCoupon';
// You could also conditionally modify existing headers, like the Reply-To.
// For instance, if you wanted to always reply to a specific support email.
// $headers[] = 'Reply-To: [email protected]';
// Return the modified headers array.
return $headers;
}, 10, 2 ); // 10 is the priority, 2 is the number of accepted arguments
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/integrations/woocommerce/actions/wc-createandemailcoupon.php:324
$headers[] = 'Bcc: ' . $bcc;
}
$headers[] = 'Content-Type: text/html; charset=UTF-8';
if ( ! empty( $reply_to ) ) {
$headers[] = "Reply-To: $reply_to";
}
$headers = apply_filters( 'automator_pro_woo_create_and_email_coupon', $headers, $this );
//$email_body = wpautop( $email_body );
$mailed = wp_mail( $to, $subject, $email_body, $headers );
if ( ! $mailed ) {
$error_message = Automator()->error_message->get( 'email-failed' );
$action_data['do-nothing'] = true;
$action_data['complete_with_errors'] = true;