Create resources that yould be shared among products

Issue #982 new
Valentina R created an issue

As staff but shared beteen products, so that when one gets booked, it’s still available in the other product.

FYI, this can now be achieved by using this code snippet:

// Make sure common capacity is shared between common products.
add_filter( 'wc_apointments_check_appointment_product', 'common_capacity_between_products', 10, 3 );
function common_capacity_between_products( $return, $appointment_id, $product_id ) {
    $appointment            = get_wc_appointment( $appointment_id );
    $appointment_product_id = (int) $appointment->get_product_id();
    $common_product_ids     = array( 811, 810 ); #product IDs with shared capacity.

    if ( $appointment_product_id !== $product_id && in_array( $product_id, $common_product_ids ) ) {
        return false;
    }

    return $return;
};

// Include all common product IDs inside appointment query.
add_filter( 'woocommerce_appointments_in_date_range_query_args', 'common_product_ids_in_date_range_query_args' );
add_filter( 'woocommerce_appointments_for_objects_query_args', 'common_product_ids_in_date_range_query_args' );
function common_product_ids_in_date_range_query_args( $args ) {
    if ( isset( $args['product_id'] ) && ! empty( $args['product_id'] ) ) {
        $product_ids        = is_array( $args['product_id'] ) ? $args['product_id'] : array( $args['product_id'] );
        $common_product_ids = array( 811, 810 ); #product IDs with shared capacity.

        // Check if queried product ID has shared capacity.
        $common_result = array_intersect( $product_ids, $common_product_ids );
        if ( $common_result ) {
            $args['product_id'] = array_unique( array_merge( $product_ids, $common_product_ids ) );
        }

    }

    return $args;
}

Requested here and has been asked before.

Comments (0)

  1. Log in to comment