Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jessepearson
Last active August 7, 2023 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jessepearson/27a0b073113b41d6b415b584cb7ad7c9 to your computer and use it in GitHub Desktop.
Save jessepearson/27a0b073113b41d6b415b584cb7ad7c9 to your computer and use it in GitHub Desktop.
Move bookings in WooCommerce Bookings to Confirmed status if they were paid for via COD.
<?php // do not copy this line
/**
* 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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment