Skip to content

Commit

Permalink
Merge branch 'trunk' into dependabot/npm_and_yarn/webpack-5.82.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vikrampm1 authored May 26, 2023
2 parents 28ac0af + 48f017e commit 55733e1
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 46 deletions.
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
*** Changelog ***

= 1.1.40 - 2023-05-12 =
* Dev - Added a new filter, `woocommerce_accommodation_booking_get_check_times`, to change the check-in/out timings per product.
* Fix - Fully booked days show as partially booked - Day after booking shows partially booked.

= 1.1.39 - 2023-03-14 =
* Dev - Bump `http-cache-semantics` from 4.1.0 to 4.1.1.

Expand Down
37 changes: 27 additions & 10 deletions includes/admin/class-wc-accommodation-booking-admin-panels.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles_and_scripts' ) );
add_filter( 'product_type_selector', array( $this, 'product_type_selector' ) );
add_filter( 'product_type_options', array( $this, 'product_type_options' ), 15 );
add_filter( 'wc_bookings_product_duration_fallback', array( $this, 'get_product_duration' ), 10, 3 );

add_action( 'woocommerce_product_data_panels', array( $this, 'panels' ) );

Expand All @@ -24,6 +25,22 @@ public function __construct() {
add_action( 'woocommerce_process_product_meta', array( $this,'save_product_data' ), 25 );
}

/**
* Filters product unit to display.
*
* @param string $duration_unit_default Default fallback duration
* @param string $duration_unit Current duration unit
* @param int $duration Duration of booking
*
* @return string
*/
public function get_product_duration( $duration_unit_default, $duration_unit, $duration ) {
if ( 'night' === $duration_unit ) {
return _n( 'night', 'nights', $duration, 'woocommerce-accommodation-bookings' );
}
return $duration_unit_default;
}

/**
* Add the accommodation booking product type
* @return array
Expand Down Expand Up @@ -201,19 +218,19 @@ public function save_product_data( $post_id ) {
case 'custom' :
$availability[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_from_date' ][ $i ] );
$availability[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_to_date' ][ $i ] );
break;
break;
case 'months' :
$availability[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_from_month' ][ $i ] );
$availability[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_to_month' ][ $i ] );
break;
break;
case 'weeks' :
$availability[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_from_week' ][ $i ] );
$availability[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_to_week' ][ $i ] );
break;
break;
case 'days' :
$availability[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_from_day_of_week' ][ $i ] );
$availability[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_availability_to_day_of_week' ][ $i ] );
break;
break;
}
}
update_post_meta( $post_id, '_wc_booking_availability', $availability );
Expand Down Expand Up @@ -262,7 +279,7 @@ public function save_product_data( $post_id ) {
update_post_meta( $post_id, '_resource_base_costs', $resource_base_costs );
update_post_meta( $post_id, '_resource_block_costs', $resource_block_costs );
}

// Rates
$pricing = array();
$original_base_cost = abs( (float) get_post_meta( $post_id, '_wc_booking_base_cost', true ) );
Expand All @@ -279,22 +296,22 @@ public function save_product_data( $post_id ) {
case 'custom' :
$pricing[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_from_date' ][ $i ] );
$pricing[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_to_date' ][ $i ] );
break;
break;
case 'months' :
$pricing[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_from_month' ][ $i ] );
$pricing[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_to_month' ][ $i ] );
break;
break;
case 'weeks' :
$pricing[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_from_week' ][ $i ] );
$pricing[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_to_week' ][ $i ] );
break;
break;
case 'days' :
$pricing[ $i ]['from'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_from_day_of_week' ][ $i ] );
$pricing[ $i ]['to'] = wc_clean( $_POST[ 'wc_accommodation_booking_pricing_to_day_of_week' ][ $i ] );
break;
break;
}
}

// Person Types
if ( isset( $_POST['person_id'] ) && isset( $_POST['_wc_booking_has_persons'] ) ) {
$person_ids = $_POST['person_id'];
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-accommodation-booking-cart-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ function add_to_cart() {
*/
public function get_item_data( $other_data, $cart_item ) {
if ( 'accommodation-booking' === $cart_item['data']->get_type() && ! empty( $other_data ) ) {
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $cart_item['product_id'] );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $cart_item['product_id'] );
$end_date = date_i18n( get_option( 'date_format'), $cart_item['booking']['_end_date'] );

if ( ! empty( $check_in ) ) {
Expand Down
6 changes: 3 additions & 3 deletions includes/class-wc-accommodation-booking-date-picker.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function __construct() {
* @return mixed
*/
public function add_accommodation_posted_data( $data, $product, $total_duration ) {
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $product->get_id() );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $product->get_id() );

if ( 'night' === $product->get_duration_unit() ) {
$data['_start_date'] = strtotime( "{$data['_year']}-{$data['_month']}-{$data['_day']} $check_in" );
Expand Down Expand Up @@ -118,7 +118,7 @@ public function add_partially_booked_dates( $booked_data_array, $product ) {
continue;
}

$check_in_time = $product->get_check_times( 'in' );
$check_in_time = $product->get_check_times( 'in', $product->get_id() );
if ( 'in' === $which ) {
$check_time = strtotime( '-1 day ' . $check_in_time, $time );
} else {
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-accommodation-booking-order-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function add_checkinout_info_to_order_email( $item_id, $item, $order ) {
return;
}

$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $item['product_id'] );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $item['product_id'] );
?>
<p>
<strong><?php esc_html_e( 'Check-in', 'woocommerce-accommodation-bookings' ); ?> </strong>
Expand Down
16 changes: 12 additions & 4 deletions includes/class-wc-accommodation-booking-product-tabs.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*/
class WC_Accommodation_Booking_Product_Tabs {

/**
* Product ID.
*/
public $product_id = 0;

/**
* Hook into WooCommerce..
*/
Expand All @@ -22,8 +27,8 @@ public function __construct() {
* @return boolean
*/
public function are_time_fields_filled_out() {
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $this->product_id );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $this->product_id );

if ( empty( $check_in ) ) {
return false;
Expand Down Expand Up @@ -56,6 +61,9 @@ public function add_time_tab( $tabs = array() ) {
return $tabs;
}

// Set the product ID.
$this->product_id = $post->ID;

if ( ! $this->are_time_fields_filled_out() ) {
return $tabs;
}
Expand All @@ -77,8 +85,8 @@ public function add_time_tab_content() {
if ( ! $this->are_time_fields_filled_out() ) {
return;
}
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $this->product_id );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $this->product_id );
?>
<h2><?php echo esc_html( apply_filters( 'woocommerce_accommodation_booking_time_tab_heading', __( 'Arriving/leaving', 'woocommerce-accommodation-bookings' ) ) ); ?></h2>
<ul>
Expand Down
11 changes: 4 additions & 7 deletions includes/class-wc-accommodation-booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ public function add_checkin_time_to_booking_start_time( $date, $booking ) {
return $date;
}

$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );

$date_format = apply_filters( 'woocommerce_bookings_date_format', wc_date_format() );
$time_format = apply_filters( 'woocommerce_bookings_time_format', ', ' . wc_time_format() );

return date_i18n( $date_format, $booking->start ) . date_i18n( $time_format, strtotime( "Today " . $check_in ) );
return date_i18n( $date_format, $booking->start ) . date_i18n( $time_format, $booking->start );
}

public function add_checkout_time_to_booking_end_time( $date, $booking ) {
Expand All @@ -123,11 +121,10 @@ public function add_checkout_time_to_booking_end_time( $date, $booking ) {
return $date;
}

$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$date_format = apply_filters( 'woocommerce_bookings_date_format', wc_date_format() );
$time_format = apply_filters( 'woocommerce_bookings_time_format', ', ' . wc_time_format() );

return date_i18n( $date_format, $booking->end ) . date_i18n( $time_format, strtotime( "Today " . $check_out ) );
return date_i18n( $date_format, $booking->end ) . date_i18n( $time_format, $booking->end );
}

/**
Expand Down Expand Up @@ -181,8 +178,8 @@ public function update_start_end_time( $booking_id ) {
return;
}

$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $product_id );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $product_id );

$start = get_post_meta( $booking_id, '_booking_start', true );
$end = get_post_meta( $booking_id, '_booking_end', true );
Expand Down
41 changes: 28 additions & 13 deletions includes/class-wc-product-accommodation-booking.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,16 @@ public function get_price_html( $price = '' ) {
public function get_time_slots( $blocks, $resource_id = 0, $from = 0, $to = 0, $include_sold_out = false ) {
$bookable_product = $this;

$transient_name = 'book_ts_' . md5( http_build_query( array( $bookable_product->get_id(), $resource_id, $from, $to ) ) );
$product_id = $bookable_product->get_id();
$transient_name = 'book_ts_' . md5( http_build_query( array( $product_id, $resource_id, $from, $to ) ) );
$available_slots = get_transient( $transient_name );
$booking_slots_transient_keys = array_filter( (array) get_transient( 'booking_slots_transient_keys' ) );

if ( ! isset( $booking_slots_transient_keys[ $bookable_product->get_id() ] ) ) {
$booking_slots_transient_keys[ $bookable_product->get_id() ] = array();
if ( ! isset( $booking_slots_transient_keys[ $product_id ] ) ) {
$booking_slots_transient_keys[ $product_id ] = array();
}

$booking_slots_transient_keys[ $bookable_product->get_id() ][] = $transient_name;
$booking_slots_transient_keys[ $product_id ][] = $transient_name;

// Give array of keys a long ttl because if it expires we won't be able to flush the keys when needed.
// We can't use 0 to never expire because then WordPress will autoload the option on every page.
Expand All @@ -229,8 +230,8 @@ public function get_time_slots( $blocks, $resource_id = 0, $from = 0, $to = 0, $
$has_resources = $bookable_product->has_resources();

foreach ( $blocks as $block ) {
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in' );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out' );
$check_in = WC_Product_Accommodation_Booking::get_check_times( 'in', $product_id );
$check_out = WC_Product_Accommodation_Booking::get_check_times( 'out', $product_id );
// Blocks for accommodation products are initially calculated as days but the actuall time blocks are shifted by check in and checkout times.
$block_start_time = strtotime( "{$check_in}", $block );
$block_end_time = strtotime( "{$check_out}", strtotime( "+1 days", $block ) );
Expand Down Expand Up @@ -328,20 +329,34 @@ public function get_blocks_in_range( $start_date, $end_date, $intervals = array(
/**
* Get checkin and checkout times.
*
* @param string $type
* @param string $type The type, check_in or check_out.
* @param int $product_id The product ID.
*
* @return string Time, either from options or default
* @return string The time, either from options or default or from the filtered value.
*/
public static function get_check_times( $type ) {
$option = get_option( 'woocommerce_accommodation_bookings_times_settings' );
public static function get_check_times( $type, $product_id = 0 ) {
$option = get_option( 'woocommerce_accommodation_bookings_times_settings' );
$check_time = '';

switch ( $type ) {
case 'in':
return isset( $option['check_in'] ) ? $option['check_in'] : '14:00';
$check_time = $option['check_in'] ?? '14:00';
break;
case 'out':
return isset( $option['check_out'] ) ? $option['check_out'] : '14:00';
$check_time = $option['check_out'] ?? '14:00';
break;
}

return '';
/**
* Filter the check-in/out times for a specific product.
*
* @param string $check_time The check-in/out time stored in the database.
* @param string $type The type, check_in or check_out.
* @param int $product_id The product ID.
*
* @return string The filtered/original time.
*/
return apply_filters( 'woocommerce_accommodation_booking_get_check_times', $check_time, $type, (int) $product_id );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "woocommerce-accommodation-bookings",
"title": "WooCommerce Accommodation Bookings",
"version": "1.1.39",
"version": "1.1.40",
"config": {
"translate": false,
"wp_org_slug": "woocommerce-accommodation-bookings",
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: woocommerce, automattic, woothemes, jshreve, akeda, bor0, jessepe
Tags: woocommerce, bookings, accommodations
Requires at least: 5.6
Tested up to: 6.1
Stable tag: 1.1.39
Stable tag: 1.1.40
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -36,6 +36,10 @@ If the prices shown on the product do not match the prices defined in the dashbo

== Changelog ==

= 1.1.40 - 2023-05-12 =
* Dev - Added a new filter, `woocommerce_accommodation_booking_get_check_times`, to change the check-in/out timings per product.
* Fix - Fully booked days show as partially booked - Day after booking shows partially booked.

= 1.1.39 - 2023-03-14 =
* Dev - Bump `http-cache-semantics` from 4.1.0 to 4.1.1.

Expand Down
4 changes: 2 additions & 2 deletions woocommerce-accommodation-bookings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Accommodation Bookings
* Plugin URI: https://woocommerce.com/products/woocommerce-accommodation-bookings/
* Description: An accommodations add-on for the WooCommerce Bookings extension.
* Version: 1.1.39
* Version: 1.1.40
* Author: WooCommerce
* Author URI: https://woocommerce.com
* Text Domain: woocommerce-accommodation-bookings
Expand All @@ -23,7 +23,7 @@
exit;
}

define( 'WC_ACCOMMODATION_BOOKINGS_VERSION', '1.1.39' ); // WRCS: DEFINED_VERSION.
define( 'WC_ACCOMMODATION_BOOKINGS_VERSION', '1.1.40' ); // WRCS: DEFINED_VERSION.

require_once( 'includes/class-wc-accommodation-bookings-plugin.php' );
$plugin = new WC_Accommodation_Bookings_Plugin( __FILE__, WC_ACCOMMODATION_BOOKINGS_VERSION );
Expand Down

0 comments on commit 55733e1

Please sign in to comment.