Skip to content

Instantly share code, notes, and snippets.

@kartikparmar
Created September 20, 2022 04:21
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 kartikparmar/a9835448146fffccdcb235d587bb8579 to your computer and use it in GitHub Desktop.
Save kartikparmar/a9835448146fffccdcb235d587bb8579 to your computer and use it in GitHub Desktop.
Sending Booking Confirmation Email After the Order Receieved - Product setup without confirmtion.
<?php
/**
* This will send the Booking Confirmation email to customer even if the product is not setup with the requires confirmation option.
*
* @param int $order_id Order Id.
*/
function bkap_send_booking_confirmation( $order_id ) {
if ( ! $order_id )
return;
// Allow code execution only once.
if ( ! get_post_meta( $order_id, '_thankyou_action_done', true ) ) {
// Get an instance of the WC_Order object.
$order = wc_get_order( $order_id );
$booking_present = false;
// Loop through order items.
foreach ( $order->get_items() as $item_id => $item ) {
$booking_id = bkap_common::get_booking_id( $item_id );
if ( $booking_id ) {
$booking_present = true;
$wc_email = WC_Emails::instance();
$email = $wc_email->emails['BKAP_Email_Booking_Confirmed'];
$email->trigger( $item_id, $booking_id );
do_action( 'bkap_booking_is_confirmed', $booking_id );
}
}
if ( $booking_present ) {
// Flag the action as done (to avoid repetitions on reload for example).
$order->update_meta_data( '_thankyou_action_done', true );
$order->save();
}
}
}
add_action( 'woocommerce_thankyou', 'bkap_send_booking_confirmation', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment