Skip to content

Instantly share code, notes, and snippets.

@gicolek
Created February 22, 2024 12:56
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 gicolek/b5152cf4b52ef5092823a30ae6286bbe to your computer and use it in GitHub Desktop.
Save gicolek/b5152cf4b52ef5092823a30ae6286bbe to your computer and use it in GitHub Desktop.
Resend WooCommerce order_id, a useful snippet
<?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