Before you start
Read Developer overview for where to put code. Pass the right number of accepted arguments to add_filter(): the filtered value counts as the first one.
This page lists only filters that run. There is no working filter on the calculated total, on passenger rates, on available dates or departures, on the booking form’s steps, or on a single email’s subject, body or recipients.
Filters in HarborBook Pro and the add-ons are in Hooks in HarborBook Pro and the add-ons.
Pricing
HarborBook calculates a price in this order: passengers, extras and pickup surcharge, then the group discount, then the early-bird discount, then harborbook/pricing/discount, then tax on the discounted amount, then harborbook/pricing/deposit.
harborbook/pricing/discount: an extra discount as an amount of money, not a percentage. Value: float, starting at0.0. Extra arguments:$subtotal(float, the running amount before tax, after the group and early-bird discounts) and$booking_data(array). Return a float. The result is capped at the running amount. It runs on every price calculation.harborbook/pricing/discount_label: the label shown for that discount. Value: string, starting empty. Extra arguments:$discount(float, the amount applied) and$booking_data(array). Return a string. It runs only when the discount is above zero.harborbook/pricing/deposit: the amount the guest must pay online now. Value: float, starting at0.00. Extra arguments:$total(float, the total including tax) and$activity_id(int). Return a float. A value above zero makes online payment required and switches pay on arrival off for that booking.
Keys in $booking_data:
- activity_id: the activity ID (int).
- slot_id: the departure ID (int).
0when no departure is chosen yet. - slot_date: the departure date as
Y-m-d, or an empty string. - passenger_count: the total number of guests (int).
0for a private booking. - passengers: an array with the keys
adult,childandinfant(ints). - booking_mode:
grouporprivate, when the caller sent it. - coupon_code: the code the guest typed, when the caller sent it.
This example gives 10 percent off departures on a Tuesday. It can go in a child theme’s functions.php or in your own plugin. Priority 20 lets it add to a discount from the Coupons add-on, which runs at priority 10.
add_filter( 'harborbook/pricing/discount', 'my_hb_tuesday_discount', 20, 3 );
add_filter( 'harborbook/pricing/discount_label', 'my_hb_tuesday_discount_label', 20, 3 );
function my_hb_is_tuesday_departure( $booking_data ) {
$slot_date = isset( $booking_data['slot_date'] ) ? (string) $booking_data['slot_date'] : '';
if ( '' === $slot_date ) {
return false;
}
$timestamp = strtotime( $slot_date . ' 00:00:00' );
return $timestamp && '2' === gmdate( 'N', $timestamp );
}
function my_hb_tuesday_discount( $discount, $subtotal, $booking_data ) {
if ( ! my_hb_is_tuesday_departure( $booking_data ) ) {
return $discount;
}
return (float) $discount + round( (float) $subtotal * 0.10, 2 );
}
function my_hb_tuesday_discount_label( $label, $discount, $booking_data ) {
if ( ! my_hb_is_tuesday_departure( $booking_data ) ) {
return $label;
}
return '' === $label ? 'Tuesday discount' : $label . ' + Tuesday discount';
}
HarborBook saves the amount from harborbook/pricing/discount in the booking’s coupon_discount column, whether it came from a coupon or from your code.
Payment rules and methods
harborbook/payment_policy/resolve: the payment rules for one price calculation. Value: array$policy. Extra arguments:$activity_id(int) and$pricing(array, the price result so far). Return the array with the same keys.harborbook/payment/methods_available: which payment methods the booking form offers. Value: array with the keysstripeandmanual(bools). Extra arguments:$activity_id(int),$pricing(array) and$policy(array). Return an array of method slug to bool.harborbook/booking/confirmation_status: the status a booking gets at the end of checkout in the booking form. Value: string,confirmedorpending. Extra arguments:$activity_id(int),$pricing(array) and$payment_method(string,stripe,manualor an add-on’s method slug). Returnconfirmedorpending. Only these two statuses send an email.harborbook/payment/zero_decimal_currencies: currencies charged without a minor unit. Value: array of upper-case currency codes. Return an array.harborbook/payment/amount_tolerance_cents: how far the charged amount may differ from the expected amount, in minor units. Value: int, default1. Return an int of zero or more.harborbook/booking/payment_invoice_html: an invoice link shown next to a payment in the admin. Value: string, starting empty. Extra arguments:$payment(array, the payment row) and$context(string,cellorinline). Return HTML. Onlyaandspantags are kept.
Keys in $policy:
- prepayment_required: the amount due online now (float).
- balance_due: the amount left to pay later (float).
- prepayment_percent: the prepayment as a percentage of the total (float).
- policy_mode:
none,partialorfull. - requires_online_pay: true when a prepayment is due (bool).
- stripe_required: true when a prepayment is due (bool).
- manual_allowed: true when no prepayment is due and pay on arrival is switched on (bool).
- can_checkout: whether checkout may go ahead (bool). Default: true.
- checkout_block_reason: a message for a blocked checkout (string). Default: empty.
- fallback_status: default
confirmed. - stripe_configured: true when a card gateway is set up (bool).
This example switches pay on arrival off for one activity. It can go in a child theme’s functions.php or in your own plugin. Guests then need another payment method for that activity, so use it only when card payments are set up.
add_filter( 'harborbook/payment_policy/resolve', 'my_hb_no_pay_on_arrival_for_activity', 10, 3 );
function my_hb_no_pay_on_arrival_for_activity( $policy, $activity_id, $pricing ) {
if ( 42 === (int) $activity_id ) {
$policy['manual_allowed'] = false;
}
return $policy;
}
This example makes every booking of one activity start as pending, so you can review it first. It can go in a child theme’s functions.php or in your own plugin.
add_filter( 'harborbook/booking/confirmation_status', 'my_hb_pending_for_activity', 10, 4 );
function my_hb_pending_for_activity( $status, $activity_id, $pricing, $payment_method ) {
if ( 42 === (int) $activity_id ) {
return 'pending';
}
return $status;
}
Card gateway
These filters connect a card gateway to HarborBook. The Stripe Payments add-on uses them. HarborBook only ever asks for the gateway with the slug stripe, so they are not a way to add a different gateway.
harborbook/payment/gateways: the registered gateway classes. Value: array, always starting empty. Return an array of slug to class name.harborbook/payment/gateway/stripe/is_configured: used only when no gateway class is registered. Value: bool, default false. Extra argument:$slug(string).harborbook/payment/gateway/stripe/publishable_key: used only when the gateway class does not supply a key. Value: string, default empty.harborbook/booking_widget/stripe_mode: which card form the booking form shows. Value: string, defaultcard_element. Returncard_elementorpayment_element.
Checkout
harborbook/checkout/confirmation: the confirmation data sent to the browser after a successful checkout in the booking form. Value: array$confirmation. Extra arguments:$payment_method(string) and$result(array, the data of the booking that was created). Return the array.harborbook/checkout/create_method_hold: lets an add-on handle a payment method of its own. Value:null. Extra arguments:$payment_method(string),$payload(array, the checkout data) and$pricing(array). Return a non-empty string ID to claim the checkout, aWP_Errorto stop it, ornullto leave it alone.harborbook/checkout/is_online_payment: whether a payment method is charged online. Value: bool, true for every method exceptmanual. Extra argument:$payment_method(string). Return a bool.harborbook/checkout/payment_intent_result: the data returned to the booking form when it starts a card payment. Value: array. Return an array.
harborbook/checkout/confirmation is the closest thing to a “new booking” hook for bookings made in the booking form, because it runs for confirmed and pending bookings alike. Useful keys in $confirmation are booking_id, booking_ref, booking_status, payment_status, total, amount_paid and balance_due. Always return $confirmation. It does not run for bookings an admin creates.
Checkout limits
harborbook/payment/intent_rate_limit: how many card checkouts one IP address may start. Value: array withlimit(default10) andwindowin seconds (default600). Return the same shape. The limit is at least 1 and the window at least 60 seconds.harborbook/payment/max_active_reservations_per_slot: how many unfinished checkouts one visitor may hold on one departure. Value: int, default2. Return an int of 1 or more.harborbook/payment/max_active_reservations_per_visitor: how many unfinished checkouts one visitor may hold across all departures. Value: int, default3. Return an int of 1 or more.harborbook/client_ip: the visitor IP address used for these limits and saved on new bookings. Value: string. Return a string.harborbook/day_trip_default_minutes: the length assumed for a day trip that has no duration set, used to work out its end time. Value: int, default480. Return an int. The minimum is 60.
Notifications
harborbook/notifications/types: the list of notification types. Value: array of type slugs. Return an array. HarborBook refuses to send a type that is not in this list.harborbook/notifications/type_labels: the names shown for each type in the settings. Value: array of type slug to label. Return the same shape.harborbook/notifications/default_templates: the default templates. Value: array of type slug to an array withsubject,html_bodyandtext_body. Return the same shape.harborbook/notifications/admin_copy_types: the types that are also sent to your admin email addresses. Value: array, defaultbooking_confirmedonly. Return an array of type slugs.harborbook/cancellation_policy/summary: the text of the{cancellation_policy}placeholder. Value:null. Return a non-empty string to use it. Otherwise the text is “Contact us for cancellation terms.”
Default templates are copied into your saved settings for any template that is still empty. After that the saved template is used, so changing a default with the filter does not change an email you have already saved.
The core types are booking_confirmed, booking_pending, booking_cancelled_by_operator, booking_weather_cancellation, booking_reminder_72h, booking_reminder_24h, booking_reminder_2h, refund_approved and review_request. Placeholders are listed in Placeholders you can use in emails.
This example also sends you a staff copy when a booking is pending, which is a simple way to hear about pending bookings. It can go in a child theme’s functions.php or in your own plugin.
add_filter( 'harborbook/notifications/admin_copy_types', 'my_hb_admin_copy_for_pending' );
function my_hb_admin_copy_for_pending( $types ) {
$types[] = 'booking_pending';
return $types;
}
This example sets your own cancellation text for emails. It can go in a child theme’s functions.php or in your own plugin. Priority 20 lets it replace the text from the Customer Portal add-on.
add_filter( 'harborbook/cancellation_policy/summary', 'my_hb_cancellation_summary', 20 );
function my_hb_cancellation_summary( $summary ) {
return 'Free cancellation up to 48 hours before departure.';
}
Booking form and front end
harborbook/should_load_widget: whether the booking form’s CSS and JavaScript load on the current page. Value: bool, true when the shortcode or block was rendered or is in the page content. Return a bool.harborbook_customer_portal_url: the address of the page where guests manage a booking. Value: string, empty unless a page is set. Extra argument:$ref(string, the booking reference, which may be empty). Return a URL without the reference. HarborBook adds?ref=itself.harborbook_countries_map: the country list. Value: array of two-letter code to country name. Return the same shape.harborbook_country_options: the country list sent to the booking form. Value: a list of arrays withcodeandlabel, sorted by label. Return the same shape.
The shortcode also passes through the WordPress filter shortcode_atts_harborbook.
Admin
harborbook/catalog_capability: the WordPress capability needed to create, edit, publish and delete activities, extras and pickup locations in the post editor and through the WordPress REST API. Value: string, defaultmanage_options. Return a capability name. It does not change who can open HarborBook’s own admin screens, which always needmanage_options.harborbook/settings/valid_tabs: the tab slugs the settings screen accepts. Value: array of slugs. Return an array.harborbook/settings/nav_items: the settings navigation. Value: a list of two-item arrays, slug first and label second. Return the same shape.harborbook/settings/tabs_without_save: the tabs that hide the main save button. Value: array of slugs. Return an array.harborbook/settings/payments/sub_tabs: the sub-tabs under Payments. Value: a list of arrays withslug,label,priorityand an optionalrender_callback. Return the same shape. Sub-tabs are sorted by priority, and the callback is called with no arguments to print the sub-tab.harborbook/settings/currencies: the currencies offered in the settings. Value: array of currency code to an array withlabel,symbol,positionandgroup. Return the same shape.harborbook/calendar/slot_payload: the data of one departure on the admin calendar. Value: array$slot. Extra argument:$slot_id(int). Return the array.harborbook/demo_content/dataset: the demo data used by the demo import. Value: array. Return an array.
An example that adds a settings tab is in Action hooks reference.
Licence and add-on switches
HarborBook asks these filters whether an add-on is present. The add-ons answer them. Read the result in your own code, and do not use the filters to switch an add-on on.
harborbook/has_addon/{slug}: whether the add-on with that slug is present. Value: bool, default false. Slugs:stripe-payments,advance-payments,coupons,customer-portal,guidesandpopup-widget.harborbook/stripe_payments/enabled,harborbook/advance_payments/enabled,harborbook/coupons/enabled,harborbook/customer_portal/enabled,harborbook/guides/enabled,harborbook/popup_widget/enabled: whether that add-on’s features are switched on. Value: bool, default the result of the matchingharborbook/has_addon/{slug}filter.
This example checks for an add-on before using it. It can go in a child theme’s functions.php or in your own plugin.
function my_hb_coupons_available() {
return class_exists( 'Harborbook_License' ) && Harborbook_License::has_addon( 'coupons' );
}