Last active
June 29, 2022 10:52
-
-
Save Jany-M/7067af91e67adef69e44 to your computer and use it in GitHub Desktop.
[WordPress] [WooCommerce] [Bookings] Auto-Confirm Booking upon Order Complete
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 | |
add_action( 'woocommerce_order_status_completed', 'mark_confirm_bookings', 20, 1 ); | |
function mark_confirm_bookings( $order_id ) { | |
global $wpdb; | |
$order = new WC_Order( $order_id ); | |
$bookings = array(); | |
foreach ( $order->get_items() as $order_item_id => $item ) { | |
if ( 'line_item' == $item['type'] ) { | |
if ( !wc_booking_requires_confirmation( $item['product_id'] ) ) { | |
$bookings = array_merge( $bookings, $wpdb->get_col( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key = '_booking_order_item_id' AND meta_value = %d", $order_item_id ) ) ); | |
} | |
} | |
} | |
foreach ( $bookings as $booking_id ) { | |
$booking = get_wc_booking( $booking_id ); | |
$booking->update_status('confirmed'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry guys... just saw all the comments (Github not sending me any notifications about comments on gists).
Keep in mind the code is from 2015, so things may have changed since then (actually, most likely, hence my snippet is not really compatible anymore).
Also, I have not used the Bookings plugin in years, so I can't really be helpful anymore about it.
If the email is now sending twice, maybe uncheck the "processing" email and only leave the completed one to be sent? or viceversa?
@mzykin About setting the product as non-virtual, not sure that's recommended, since it's a Booking and not a physical product?
@Xyala Sorry, I really wouldn't know, haven't used that plugin in years.