Maybe somebody had similar issue with WooCommerce...
In my shop I have Przelewy24 payment gate. When user chooses to pay with that gate, a new order in woo is created with status 'pending payment'.
The problem is that woo cannot send order confirmation mail in that state. So user never receives any confirmation from us. Only if payment is successful and order has been processed.
I have PayU another payment gateway that sets new order status to "On Hold" and order confirmation is sent. Unfortunately, Przelewy24 support is unable to help and I can't change that status.
What I want to achieve is to force woo to send order confirmation mail to the client if order is paid using Przelewy24 gate and order is in Pending Payment state.
First, you will need to get the payment ID for "Przelewy24", for that see this answer.
Now to allow sending a notification to the customer for orders using Przelewy24 payment, you need to change the order status from "pending" to "on-hold". The following code is based on this answer and should do the job.
In the code below, replace przelewy24
by the right payment ID (if it doesn't match):
add_action( 'woocommerce_thankyou', 'change_order_status_for_przelewy24_payments', 20 );
function change_order_status_for_przelewy24_payments( $order_id ) {
if ( ! $order_id )
return;
// Get an instance of the WC_Product object
$order = wc_get_order( $order_id );
// No updated status for orders delivered with Bank wire, Cash on delivery and Cheque payment methods.
if ( $order->get_payment_method() === 'przelewy24' ) {
$order->update_status('on-hold');
}
}
It should work, changing order status to "on-hold and sending a notification to the customer.
Or maybe even better, without changing the order status, sending an email notification to the customer and the admin.
Here, take care to change in the hook woocommerce_thankyou_przelewy24
the "przelewy24" sub-string, with the correct payment ID for Przelewy24 (if it doesn't match):
add_action( 'woocommerce_thankyou_przelewy24', 'send_pending_order_notification', 20 );
function send_pending_order_notification( $order_id ) {
if ( ! $order_id )
return;
// Get an instance of the WC_Product object
$order = wc_get_order( $order_id );
// Only for "pending" order status and 'przelewy24' payements
if ($order->has_status('pending') ) {
// Send "New Email" notification (to admin)
WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger($order_id);
// Send "On Hold Email" notification (to customer)
WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger($order_id);
}
}
It should work without changing order status, sending a notification to the customer (and the admin), and will not send this notification if the order has a "failed" status.
Based on this answer, without changing the order status, you can use the following to send an email notification to the customer (and the admin too).
In the code below, replace przelewy24
by the right payment ID (if it doesn't match):
add_action( 'woocommerce_checkout_order_processed', 'pending_order_notification_for_przelewy24', 20, 3 );
function pending_order_notification_for_przelewy24( $order_id, $posted_data, $order ) {
// Here set the related Payment ID
$payment_id = 'przelewy24';
// Only for "pending" order status and 'przelewy24' payements
if ($order->has_status('pending') && $order->get_payment_method() === $payment_id) {
// Send "New Email" notification (to admin)
WC()->mailer()->get_emails()['WC_Email_New_Order']->trigger($order_id);
// Send "On Hold Email" notification (to customer)
WC()->mailer()->get_emails()['WC_Email_Customer_On_Hold_Order']->trigger($order_id);
}
}
It should work without changing order status, sending a notification to the customer (and the admin). But this will handle Przelewy24 failed orders.