Skip to content

Instantly share code, notes, and snippets.

@maddisondesigns
Created May 23, 2024 04:31
Show Gist options
  • Save maddisondesigns/58a86f7b5944a1ab10f08c13b73e8abc to your computer and use it in GitHub Desktop.
Save maddisondesigns/58a86f7b5944a1ab10f08c13b73e8abc to your computer and use it in GitHub Desktop.
Perform action/email when a WooCommerce order is placed on-hold
<?php
/**
* Perform action/email when a WooCommerce order is placed on-hold
*/
function wps_woocommerce_order_status_changed( $order_id, $checkout = null ) {
global $woocommerce;
$to = 'your-email@yourdomain-name.com';
$subject = '';
$body = '';
$headers = array('Content-Type: text/html; charset=UTF-8');
$order = new WC_Order( $order_id );
if($order->status == 'on-hold'){
$subject = 'Order #' . $order_id . ' has been placed on-hold';
$body = '<p><strong>WooCommerce Order <a href="' . home_url( '/' ) . 'wp-admin/post.php?post=' . $order_id . '&action=edit" target="_blank">#' . $order_id . '</a> has been placed on-hold' . '</strong></p>';
$body .= '<p>';
$body .= $order->get_billing_first_name() . ' ' . $order->get_billing_last_name() . '<br />';
$body .= $order->get_billing_company() . '<br />';
$body .= '</p>';
$body .= '<p>';
$body .= '<strong>Address:</strong><br />';
$body .= $order->get_billing_address_1() . '<br />';
if( !empty( $order->get_billing_address_2() ) ) {
$body .= $order->get_billing_address_2() . '<br />';
}
$body .= $order->get_billing_city() . ' ' . $order->get_billing_state() . ' ' . $order->get_billing_postcode() . '<br />';
$body .= $order->get_billing_country() . '<br />';
$body .= '</p>';
$body .= '<p>';
$body .= '<strong>Email:</strong><br />';
$body .= $order->get_billing_email();
$body .= '</p>';
$body .= '<p>';
$body .= '<strong>Phone:</strong><br />';
$body .= $order->get_billing_phone();
$body .= '</p>';
wp_mail( $to, $subject, $body, $headers );
}
}
add_action('woocommerce_order_status_changed','wps_woocommerce_order_status_changed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment