Created
February 22, 2024 12:56
-
-
Save gicolek/b5152cf4b52ef5092823a30ae6286bbe to your computer and use it in GitHub Desktop.
Resend WooCommerce order_id, a useful snippet
This file contains hidden or 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 | |
/** | |
* Trigger WooCommerce order email programatically. | |
* | |
* @param INT order_id - WooCommerce WC_Order order id | |
*/ | |
function prefix_send_woocommerce_order_emails( $order_id ) { | |
$wc_emails = WC()->mailer()->get_emails(); | |
if ( empty( $wc_emails ) ) return; | |
$order = wc_get_order( $order_id ); | |
if( !( $order instanceof WC_Order ) ) return; | |
if ( $order->has_status( 'on-hold' ) ) | |
$email_id = 'customer_on_hold_order'; | |
elseif ( $order->has_status( 'processing' ) ) | |
$email_id = 'customer_processing_order'; | |
elseif ($order->has_status( 'completed' ) ) | |
$email_id = 'customer_completed_order'; | |
else | |
$email_id = "nothing"; | |
foreach ($wc_emails as $wc_mail ) | |
if ( $wc_mail->id == $email_id ) | |
$wc_mail->trigger( $order->get_id() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment