Skip to content

Instantly share code, notes, and snippets.

@michaeldoye
Last active October 27, 2015 09:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldoye/0f1f77cbafda10c981ff to your computer and use it in GitHub Desktop.
Save michaeldoye/0f1f77cbafda10c981ff to your computer and use it in GitHub Desktop.
Send custom notification on order status page - with payment link
<?php
add_action("woocommerce_order_status_changed", "my_notification");
function my_notification($order_id) {
global $woocommerce;
$order = new WC_Order( $order_id );
// Set you own custom order status here
// NOTE - payment link only works for pending or unpaid orders
if($order->status === 'pending' ) {
//Generate a payment URL
$payment_page = $order->get_checkout_payment_url();
// Create a mailer
$mailer = $woocommerce->mailer();
$message_body = __( 'My message to the shopper with payment <a href="'.$payment_page.'">link</a>' );
$message = $mailer->wrap_message(
// Message head and message body.
sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message_body );
// Send email
$mailer->send( $order->billing_email, sprintf( __( 'Order %s received' ), $order->get_order_number() ), $message );
// Set status to pending payment (if you are using a custom staus above)
$order->update_status('pending');
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment