Im looking to set up an 'event listener" in wordpress that makes use of wp_mail. Basically, I have a custom content type I created. it has fields of the following:
order_status = Order status. Will be one of these values
Possible Values: Assembly, Shipped, Ready to Ship, Manufacturing, Queued
customer_email = Customer's email address (text entry)
customer = Customer's name
Basically, the way i want it set up is that when order_status gets changed to "Ready to Ship", wp_mail would send out an email like this:
Subject: Your order is ready to ship!
Body: Dear $customer,To ensure a jump on delivery time, you can send payment for the item to be shipped out as early as tomorrow.... (etc...)
However, if the order_status is changed to Queued, than they might get an email like this:
Subject: Your order is queued into our system
Body: Dear $customer,At this time, your order is queued for our lab's creation process. Please check our page for more details.
Thanks.
************
So far, the closest I can deduce to make this possible is to put this in my theme's function.php:
<?php
$ready_to_ship = get_custom_field('order_status');
$to = get_custom_field('customer_email');
$customer_name = get_custom_field('customer');
if (update_{$ready_to_ship}_meta === 'SHIPPED') {
$subject = 'Your order is ready to ship!';
$message = 'Dear ' . $customer_name . ': Your order is ready to ship. ';
wp_mail( $to, $subject, $message);
}
?>
Am I on the right track, or should I use
if (updated_{$ready_to_ship}_meta === 'SHIPPED') {