Option to have different products & staff members, but only 1 place for all of them

Issue #407 resolved
Valentina R created an issue

Example of usage: 1 studio, 3 staff members with custom availability, 5 products. When Product A is booked for StaffA, all products should be unavailable for that slot - because they share the same studio (one and only).

Would it be possible to add a hook to make this possible?

Asked here: https://bookingwp.com/forums/topic/multiple-services-one-studio-single-quantity/

Comments (2)

  1. Fred Fontane

    Hi Zeljan,

    Following our email conversation, I am checking how are we doing with the implementation of the hook to the plugin?

    Many thanks,

    Fred

  2. Željan Topić

    Here's the code you can use to have products share the capacity:

    add_filter( 'woocommerce_appointments_time_slot', 'bookingwp_common_capacity_for_product_and_staff', 10, 6 );
    function bookingwp_common_capacity_for_product_and_staff( $available_slot, $slot, $qty_scheduled_in_slot, $available_qty, $staff, $appointable_product ) {
        $product_ids        = array( $appointable_product->get_id() );
        $product_qty_a      = $appointable_product->get_available_qty(); #available qty without scheduled slots.
        $product_qty_s      = $staff[0]; #available qty with scheduled slots.
        $common_product_ids = array( 6739, 6740 ); #product IDs with shared capacity.
        $common_product_r   = array_intersect( $product_ids, $common_product_ids );
        $staff_ids          = is_array( $staff ) ? $staff : array( $staff );
        $common_staff_ids   = array( 2, 3, 4 ); #staff IDs with shared capacity.
        $common_staff_r     = array_intersect( $staff_ids, $common_staff_ids );
        $zero_capacity      = array(
            'scheduled' => $qty_scheduled_in_slot,
            'available' => 0,
            'staff'     => array( 0 => 0),
        );
    
        // Check if queried product ID or staff ID has shared capacity.
        if ( $product_qty_s < $product_qty_a && ( $common_product_r || $common_staff_r ) ) {
            return $zero_capacity;
        } elseif ( $qty_scheduled_in_slot && ( $common_product_r || $common_staff_r ) ) {
            return $zero_capacity;
        }
    
        return $available_slot;
    }
    

    Change IDs "6739, 6740" with your own product IDs and "2, 3, 4" with your own staff IDs.

  3. Log in to comment