Filter
uncanny-automator-pro
automator_woocommerce_coupon_email_subject
Filters the subject line of WooCommerce coupon emails sent by the Automator plugin.
add_filter( 'automator_woocommerce_coupon_email_subject', $callback, 10, 2 );
Description
Filters the email subject for WooCommerce coupons sent by Uncanny Automator. This hook allows developers to dynamically modify the subject line before it's sent. It's triggered when a coupon is created and emailed as part of an Automator recipe. The `$coupon_id` parameter provides context for the coupon being processed.
Usage
add_filter( 'automator_woocommerce_coupon_email_subject', 'your_function_name', 10, 2 );
Parameters
-
$subject(mixed) - This parameter contains the coupon's email subject line, which can be customized.
-
$coupon_id(mixed) - This parameter holds the subject line of the email that will be sent to the customer with the coupon.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the automator_woocommerce_coupon_email_subject filter.
* This filter allows you to modify the subject line of the coupon email sent by Uncanny Automator.
*
* In this example, we'll add a prefix to the subject line if the coupon is for a specific amount.
*
* @param string $subject The current email subject.
* @param int $coupon_id The ID of the WooCommerce coupon.
* @return string The modified email subject.
*/
add_filter( 'automator_woocommerce_coupon_email_subject', function( $subject, $coupon_id ) {
// Check if the coupon exists.
$coupon = new WC_Coupon( $coupon_id );
if ( $coupon && $coupon->get_amount() > 0 ) {
// If the coupon has a positive amount, add a special prefix.
$subject = '[SPECIAL OFFER] ' . $subject;
}
return $subject;
}, 10, 2 ); // Priority 10, accepts 2 arguments ($subject, $coupon_id)
?>
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:299
$cc = Automator()->parse->text( $action_data['meta']['EMAILCC'], $recipe_id, $user_id, $args );
$bcc = Automator()->parse->text( $action_data['meta']['EMAILBCC'], $recipe_id, $user_id, $args );
$subject = $action_data['meta']['EMAILSUBJECT'];
$subject = str_ireplace( '{{coupon_code}}', get_the_title( $coupon_id ), $subject );
$subject = str_ireplace( '{{coupon_amount}}', $coupon_amount, $subject );
$subject = str_ireplace( '{{coupon_expiry_date}}', $coupon_expiry_date, $subject );
$subject = str_ireplace( '{{coupon_minimum_spend}}', $minimum_spend, $subject );
$subject = apply_filters( 'automator_woocommerce_coupon_email_subject', $subject, $coupon_id );
$subject = Automator()->parse->text( $subject, $recipe_id, $user_id, $args );
$email_body = $action_data['meta']['EMAILBODY'];
$email_body = str_ireplace( '{{coupon_code}}', get_the_title( $coupon_id ), $email_body );
$email_body = str_ireplace( '{{coupon_amount}}', $coupon_amount, $email_body );
$email_body = str_ireplace( '{{coupon_expiry_date}}', $coupon_expiry_date, $email_body );
$email_body = str_ireplace( '{{coupon_minimum_spend}}', $minimum_spend, $email_body );
$email_body = apply_filters( 'automator_woocommerce_coupon_email_body', $email_body, $coupon_id );