Filter uncanny-automator-pro

automator_woocommerce_coupon_email_body

Filters the email body content for WooCommerce coupon notifications, allowing modification of the message sent.

add_filter( 'automator_woocommerce_coupon_email_body', $callback, 10, 2 );

Description

Filters the email body for WooCommerce coupons sent by Uncanny Automator. Developers can modify the coupon email's content before it's sent, allowing for dynamic customization of messages and inclusion of coupon-specific details. This hook is applied after initial template variables are processed.


Usage

add_filter( 'automator_woocommerce_coupon_email_body', 'your_function_name', 10, 2 );

Parameters

$email_body (mixed)
This parameter holds the main content of the coupon email body, which can be dynamically modified.
$coupon_id (mixed)
This parameter contains the HTML content of the coupon email body, which can be modified by the filter.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to use the automator_woocommerce_coupon_email_body filter.
 * This example adds a disclaimer to the coupon email body if the coupon is a percentage discount.
 */
add_filter(
	'automator_woocommerce_coupon_email_body',
	function ( $email_body, $coupon_id ) {
		// Get the WC_Coupon object for easier access to its properties.
		$coupon = new WC_Coupon( $coupon_id );

		// Check if the coupon is a percentage discount.
		if ( 'percent' === $coupon->get_discount_type() ) {
			$email_body .= '<p><strong>Disclaimer:</strong> This is a percentage discount and applies to the subtotal of your order.</p>';
		}

		// Always return the modified email body.
		return $email_body;
	},
	10, // Priority: Default priority.
	2  // Accepted args: $email_body and $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:306

$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 );
		$email_body = Automator()->parse->text( $email_body, $recipe_id, $user_id, $args );
		$email_body = do_shortcode( $email_body );

		$headers[] = 'From: <' . $from . '>';

		if ( ! empty( $cc ) ) {
			$headers[] = 'Cc: ' . $cc;


Scroll to Top