Send rejected coupon notification email
Does anyone know how to send a rejected coupon notification email to the coupon owner when a coupon is rejected / trashed?
@laura came up with code for how to do it in Classipress - (
https://forums.appthemes.com/report-...to-email-32609), I'm looking to do the same for clipper.
I guess it would be very similar to code that sends an *approved* coupon notification email to coupon owner found in themes/clipper/includes/emails.php i.e.
/**
* Sends approved coupon notification email to coupon owner.
*
* @param object $post
*
* @return void
*/
function clpr_notify_coupon_owner_email( $post ) {
global $current_user;
if ( $post->post_type != APP_POST_TYPE ) {
return;
}
// Check that the coupon was not approved by the owner
if ( $post->post_author == $current_user->ID ) {
return;
}
$coupon_title = stripslashes( $post->post_title );
$coupon_author = stripslashes( clpr_get_user_name( $post->post_author ) );
$coupon_author_email = stripslashes( get_the_author_meta( 'user_email', $post->post_author ) );
// check to see if ad is legacy or not
if ( get_post_meta( $post->ID, 'email', true ) ) {
$mailto = get_post_meta( $post->ID, 'email', true );
} else {
$mailto = $coupon_author_email;
}
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
// we want to reverse this for the plain text arena of emails.
$blogname = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
$subject = __( 'Your Coupon Has Been Approved', APP_TD );
$message = html( 'p', sprintf( __( 'Hi %s,', APP_TD ), $coupon_author ) ) . PHP_EOL;
$message .= html( 'p', sprintf( __( 'Your coupon, "%s" has been approved and is now live on our site.', APP_TD ), $coupon_title ) ) . PHP_EOL;
$message .= html( 'p', __( 'You can view your coupon by clicking on the following link:', APP_TD ) . '<br />' . html_link( get_permalink( $post->ID ) ) ) . PHP_EOL;
$message .= html( 'p',
__( 'Regards,', APP_TD ) . '<br />' .
sprintf( __( 'Your %s Team', APP_TD ), $blogname ) . '<br />' .
html_link( home_url( '/' ) )
) . PHP_EOL;
$email = array( 'to' => $mailto, 'subject' => $subject, 'message' => $message );
$email = apply_filters( 'clpr_email_user_coupon_approved', $email, $post );
appthemes_send_email( $email['to'], $email['subject'], $email['message'] );
}
add_action( 'pending_to_publish', 'clpr_notify_coupon_owner_email', 10, 1 );
add_action( 'draft_to_publish', 'clpr_notify_coupon_owner_email', 10, 1 );