WooCommerce Bookings插件:如何设置前端可用性需管理员确认后更新
Hey there! Let’s dig into this WooCommerce Bookings issue you’re dealing with. It’s definitely frustrating when you flip the "requires admin approval" switch but the calendar still locks dates right after someone adds a booking to their cart—let’s fix that.
Why This Happens
By default, WooCommerce Bookings counts all pending/unconfirmed bookings as "occupied" when calculating availability, even if you’ve enabled admin approval. The plugin’s default logic includes every booking status except canceled, which is why your calendar updates immediately instead of waiting for your green light.
Step-by-Step Solution
We’ll use two WordPress filters to tweak the availability calculation so it only considers confirmed bookings (and ignores pending ones, plus uncheckout cart bookings).
1. Exclude Pending Bookings from Availability Checks
Add this code to your theme’s functions.php file (or use a custom code plugin like Code Snippets for safety—this avoids losing changes when your theme updates):
add_filter( 'woocommerce_bookings_get_availability_booking_ids', 'exclude_pending_bookings_from_availability', 10, 2 ); function exclude_pending_bookings_from_availability( $booking_ids, $args ) { // Only modify frontend availability checks if ( isset( $args['product_id'] ) && ! is_admin() ) { // Grab all pending bookings for the current product $pending_bookings = get_posts( array( 'post_type' => 'wc_booking', 'post_status' => 'pending', 'meta_key' => '_booking_product_id', 'meta_value' => $args['product_id'], 'fields' => 'ids', 'posts_per_page' => -1, ) ); // Remove pending bookings from the list that blocks dates $booking_ids = array_diff( $booking_ids, $pending_bookings ); } return $booking_ids; }
2. Ignore Unconfirmed Cart Bookings
If users can add bookings to their cart without checking out, those temporary cart entries might still lock dates. Add this second snippet to prevent that:
add_filter( 'woocommerce_bookings_get_cart_bookings_for_availability', 'exclude_cart_pending_bookings', 10, 1 ); function exclude_cart_pending_bookings( $cart_bookings ) { // Only apply this on the frontend if ( ! is_admin() ) { // Filter out any cart bookings that aren't fully confirmed $cart_bookings = array_filter( $cart_bookings, function( $booking ) { if ( isset( $booking['booking_id'] ) ) { $booking_post = get_post( $booking['booking_id'] ); return $booking_post && $booking_post->post_status === 'confirmed'; } return false; } ); } return $cart_bookings; }
How to Test
- Have User A add a booking (e.g., April 1-15) to their cart, complete checkout, and leave the booking in pending status.
- Switch to a different browser/incognito window as User B and check the product calendar—those dates should still show as available.
- Go to your WordPress admin, find the pending booking, and mark it as confirmed.
- Refresh the frontend calendar as User B—now the April 1-15 dates should be locked.
Quick Notes
- Always backup your
functions.phpfile before adding code, just in case something goes wrong. - If you use a caching plugin (like WP Rocket or W3 Total Cache), clear your cache after adding the snippets to see changes immediately.
- If the code doesn’t work, check for conflicts with other plugins or your theme—try disabling other plugins temporarily to narrow it down.
内容的提问来源于stack exchange,提问作者Joshua Robar

