Automatically set new booking status to confirmed

Hello,

I have created a woocommerce booking website for my new yoga studio.

When clients choose to make a new booking by paying “Cash on Delivery” the booking status is automatically set to unpaid.

However, I would like to automatically set it to “confirmed”.

I have tried to add custom code to my functions.php file but they don’t work.

add_action( 'woocommerce_new_booking', 'auto_confirm_cod_bookings', 10, 1 );

function auto_confirm_cod_bookings( $booking_id ) {
$booking = new WC_Booking( $booking_id );
$order = $booking->get_order();

if ( $order && $order->get_payment_method() === 'cod' ) {
// Change status to confirmed
$booking->update_status( 'confirmed' );
}
}

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer