WooCommerce Bookings performance fix

After doing some quick query watching and code review of the WC_Bookings_Controller, I noticed that find_booked_day_blocks() (line 96 I believe) gets ALL of the booking statuses, and therefore ALL of a site’s bookings both past and present. In our case, with Drivr, that was thousands of bookings.

$booking_statuses = get_wc_booking_statuses();

To do things like build the calendar, which uses find_booked_day_blocks(), there is no need to get ‘complete’ bookings. A quick way to accomplish this is to add the following line immediately after the previous line:

$booking_statuses = array_diff( $booking_statuses, array( 'complete' ) );

This will ultimately remove ‘complete’ bookings from being queried, and will prevent performance degradation over time. I’ve submitted the fix to WooThemes and was assured that:

“This issue has been fixed and will be included in the next version which will be released soon.”

Handling mobile redirects in .htaccess for iPhones/Androids and tablets

Below is code I put into my .htaccess to set an environment variable to change the content/theme for mobile users.


# Mobile
SetEnvIf User-Agent "Mobile" IS_MOBILE
SetEnvIf User-Agent "Googlebot-Mobile" IS_MOBILE
SetEnvIf User-Agent "BlackBerry" IS_MOBILE
SetEnvIf User-Agent "iPod" IS_MOBILE
SetEnvIf User-Agent "iPhone" IS_MOBILE
SetEnvIf User-Agent "NetFront" IS_MOBILE
SetEnvIf User-Agent "Symbian OS" IS_MOBILE
SetEnvIf User-Agent "Windows Phone" IS_MOBILE

Notice that ‘Android’ is not present in the User-Agent check. While testing with a Galaxy Nexus and Nexus 7, I noticed that the easiest way to tell the difference between Android on phones vs. Android on tablets was to check for ‘Mobile’.

From here I can access IS_MOBILE via PHP like so:


if (isset($_SERVER['IS_MOBILE'])) {
include('index-mobile.php');exit;
}

'Word document' and 'website' don't really go together…