Skip to content

Instantly share code, notes, and snippets.

@MjHead
Last active January 17, 2024 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MjHead/876fb64595c1f12069c747ee15df0c5b to your computer and use it in GitHub Desktop.
Save MjHead/876fb64595c1f12069c747ee15df0c5b to your computer and use it in GitHub Desktop.
JetBooking. Connect Guests number filter to Guests field in the form.
<?php
/**
* Instructions:
*
* 1. Create a filter for guests number - https://tppr.me/H7Sjzs, https://tppr.me/D5jImO
* 2. In the example below used 'max_guests' query variable for filter, you need replace it with your own.
* You need to do this under 'Replace this with your filter variable' comment
* 3. After this - each time when this filter applied - selected value will be stored, now you need to apply it in form
* 4. Set this value as default for Guessts field in the form - https://tppr.me/vwdRCV.
* 5. For the form keep the query var name from example - _booking_guests_num - here will be stored selected filter value
*/
add_filter( 'jet-smart-filters/query/final-query', function( $query ) {
// Replace this with your filter variable
$query_var = 'max_guests';
$store_type = jet_abaf()->settings->get( 'filters_store_type' );
foreach ( $query['meta_query'] as $index => $meta_query ) {
if ( isset( $meta_query['key'] ) && $query_var === $meta_query['key'] ) {
jet_abaf()->stores->get_store( $store_type )->set( '_booking_guests_num', $meta_query['value'] );
}
}
return $query;
} );
add_action( 'init', function() {
$store_type = jet_abaf()->settings->get( 'filters_store_type' );
$guests_num = jet_abaf()->stores->get_store( $store_type )->get( '_booking_guests_num' );
if ( $guests_num ) {
$_GET['_booking_guests_num'] = $guests_num;
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment