Plugin Support
Taha
(@tahaamin)
Hello @procespartners,
Thank you for your patience.
You can achieve this using the following code snippet. Here are the steps:
- Create a new custom email for “Backorder”.
- Set the Trigger to “New Order (Any Status)”.
- In the code below, replace
$backorder_email_id = 1; with the actual #ID of your newly created Backorder custom email.
- You can continue using your existing “Processing Order” email for orders with sufficient stock.
Code Snippet:
add_filter( 'alg_wc_custom_emails_do_send_order_email', 'alg_wc_custom_email_backorder', 10, 3);
function alg_wc_custom_email_backorder( $do_send, $email, $order ) {
$backorder_email_id = 1;
if ( $backorder_email_id !== $email->alg_wc_ce_id ) {
return $do_send;
}
foreach ( $order->get_items() as $item ) {
if ( ! is_callable( array( $item, 'get_product' ) ) ) {
continue;
}
$product = $item->get_product();
if (
$product &&
$product->backorders_require_notification() &&
$product->is_on_backorder( $item->get_quantity() )
) {
return true; // Send email
}
}
return false; // Don't send email if no backorder products found
}
Please let me know if this works for you.
Best regards,