Last active
January 17, 2024 14:27
-
-
Save MjHead/876fb64595c1f12069c747ee15df0c5b to your computer and use it in GitHub Desktop.
JetBooking. Connect Guests number filter to Guests field in the form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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