Last active
October 27, 2015 09:52
-
-
Save michaeldoye/0f1f77cbafda10c981ff to your computer and use it in GitHub Desktop.
Send custom notification on order status page - with payment link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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