Created
March 9, 2018 16:25
-
-
Save woogists/49699994022483f25402994ab0628208 to your computer and use it in GitHub Desktop.
[WooCommerce Bookings] Automatically confirm bookings purchased via COD
This file contains 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
/** | |
* Will put bookings into a Confirmed status if they were paid for via COD. | |
* | |
* @param int $order_id The order id | |
*/ | |
function set_cod_bookings_confirmed_20170825( $order_id ) { | |
// Get the order, then make sure its payment method is COD. | |
$order = wc_get_order( $order_id ); | |
if ( 'cod' !== $order->get_payment_method() ) { | |
return; | |
} | |
// Call the data store class so we can get bookings from the order. | |
$booking_data = new WC_Booking_Data_Store(); | |
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order_id ); | |
// If we have bookings go through each and update the status. | |
if ( is_array( $booking_ids ) && count( $booking_ids ) > 0 ) { | |
foreach ( $booking_ids as $booking_id ) { | |
$booking = get_wc_booking( $booking_id ); | |
$booking->update_status( 'confirmed' ); | |
} | |
} | |
} | |
add_action( 'woocommerce_order_status_processing', 'set_cod_bookings_confirmed_20170825', 20 ); |
Unfortunately still haven't figured this out. Tried different mailproviders, but the problem stays. Installed a mail-log and saw the mail is actually sent twice from our system. Hope someone can help me (and probably many others) with this. Thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great and very welcome functionality, but when I add this snippet to the functions.php the confirmation e-mail is send twice. How to fix this?