Italian (Italy)
Knowledge Base  >  Vik Appointments  >  Hook  >  Pacchetti  >  Validate Mandatory Compliance

apply_filters( 'vikappointments_validate_mandatory_package_compliance', bool|null $compliant, VAPCartItem $item, VAPCart $cart )

Fires while checking whether the package purchase is mandatory for the booked service.


Description

This hook can be used to check whether the service we are going to book requires the purchase of a package before proceeding.
NOTE: this hook doesn't fire in case the global Mandatory Purchase setting is disabled.

Parameters

$compliant

(bool|null)  By returning TRUE, the system will immediately mark the selected service as bookable, without checking the existing package purchases. By returning FALSE, the system will block the booking process for the selected service. By returning NULL, the system will proceed with the standard validation.

$item

(VAPCartItem)  The cart item to validate.

$cart

(VAPCart)  The current cart instance.


Example

This example skips the mandatory purchase of the packages for all the services that don't belong to a specific group ID.

/**
 * Checks whether a cart item (service) is compliant with the mandatory
 * package setting. Triggers only when globally enabled.
 *
 * @param  bool|null    $compliant  True to ignore the validation, false in case
 *                                  the item is not compliant, null to fallback
 *                                  to the default validation.
 * @param  VAPCartItem  $item       The cart item to validate.
 * @param  VAPCart      $cart       The cart instance.
 */
add_filter('vikappointments_validate_mandatory_package_compliance', function($compliant, $item, $cart) {
    // fetch service ID from item details
    $serviceId = $item->getServiceID();
    // fetch service details
    $service = JModelVAP::getInstance('service')->getItem($serviceID);

    // define here the list of group IDs owning services with
    // mandatory purchase of packages
    $groupsWithMandatoryPurchase = [
    	1, 2, 3
    ];

    // in case the service group is NOT inside our list, ignore
    // mandatory purchase validation
    if (!in_array($service->id_group, $groupsWithMandatoryPurchase)) {
    	return true;
    }

    // return NULL to preserve normal behavior for services requiring
    // the mandatory purchase of the packages
    return $compliant;
}, 10, 3);

Changelog

Version Description
1.2.11 Introduced.
Ultimo aggiornamento: 5 giorni fa
Utile?