Change Bookings from Daily to Monthly

We need to change the bookings from daily calculations to monthly as all of our properties are monthly and need to set up recurring payments without the prices being doubled.

Please try using this code snippet, it sets the checkout quantity to 1 regardless of how many days were selected in the date picker:

add_action( 'woocommerce_before_calculate_totals', 'hp_reset_booking_quantity' );

function hp_reset_booking_quantity( $cart ) {
  remove_action( 'woocommerce_before_calculate_totals', 'hp_reset_booking_quantity' );

  foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
    if ( isset( $cart_item['hp_booking'] ) ) {
      $cart->set_quantity( $cart_item_key, 1 );
    }
  }
}

If you set the 30-day restriction for listings this may be ok as a workaround for monthly payments. You can also change the “$123 / day” price format via Loco Translate How to translate an extension - HivePress Help Center

Hi there,

Thank you for this. Unfortunately this doesn’t work because it is setting the quantity to “1”, despite when you book multiple months. Is there any way to set it so the calendar still affects the quantity?

Please try this code snippet instead it sets the quantity to 1 or divides it by 30 for multi-month bookings:

add_action( 'woocommerce_before_calculate_totals', 'hp_reset_booking_quantity' );

function hp_reset_booking_quantity( $cart ) {
  remove_action( 'woocommerce_before_calculate_totals', 'hp_reset_booking_quantity' );

  foreach ( $cart->get_cart() as $cart_item_key => $cart_item ) {
    if ( isset( $cart_item['hp_booking'] ) ) {
		
		$count = intval(round($cart_item['quantity'] / 30));
		
		if(0 === $count){
			$count = 1;
		}
		
      $cart->set_quantity( $cart_item_key, $count );
    }
  }
}

Hi there, thank you for this. Unfortunately, it is still not working for multiple bookings as it still sets the quantity to one regardless of the length of stay.

Please try this one instead, I tested it locally and it seems to be ok:

function hp_reset_booking_quantity() {
	foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
		if ( isset( $cart_item['hp_booking'] ) ) {

			$count = intval( round( $cart_item['quantity'] / 30 ) );

			if ( 0 === $count ) {
				$count = 1;
			}

			WC()->cart->set_quantity( $cart_item_key, $count );
		}
	}
}

add_action( 'woocommerce_add_to_cart', 'hp_reset_booking_quantity' );

Hi there,

Thank you for this. It does appear that it aligns with the amount of months booked. However, in order for this to work for our system - where the goal is to have monthly booking with automatic recurring payment, how do we get the woocommerce subscriptions recurring payment to end in alignment with the end of booking? Without it aligning with the booking system, it would just continue to charge clients with no end.

Thank you

Sorry, there’s no simple solution or workaround for this in the current version - the Bookings extension doesn’t have recurring billing and monthly-based bookings, the suggested core snippet just changes the checkout quantity to monthly-based (instead of day-based). If this extension doesn’t work for your project and the purchase was made within 30 days or less please let us know via email support@hivepress.io

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.