Skip to content

Instantly share code, notes, and snippets.

@LaxusCroco
LaxusCroco / end-date-jetbooking.php
Created November 15, 2023 14:22
Set the last available date in the JetBooking calendar. Change the '2023-12-31' to the needed date
<?php
add_action( 'wp_head', function () { ?>
<script>
jQuery( document ).on( 'jet-booking/init', () => {
window.jetBookingState.filters.add( "jet-booking/input/config", modifyBookingConfig );
window.jetBookingState.filters.add( "jet-booking/calendar/config", modifyBookingConfig );
@LaxusCroco
LaxusCroco / block-bookings-next-year.php
Created November 15, 2023 14:24
Allow bookings only in the current year
<?php
add_action( 'wp_head', function () { ?>
<script>
jQuery( document ).on( 'jet-booking/init', () => {
window.jetBookingState.filters.add( "jet-booking/input/config", modifyBookingConfig );
window.jetBookingState.filters.add( "jet-booking/calendar/config", modifyBookingConfig );
@LaxusCroco
LaxusCroco / limit-bookings-to-year-in-advance.php
Last active November 15, 2023 14:29
Allow reservations only one year in advance.
<?php
add_action( 'wp_head', function () { ?>
<script>
jQuery( document ).on( 'jet-booking/init', () => {
window.jetBookingState.filters.add( "jet-booking/input/config", modifyBookingConfig );
window.jetBookingState.filters.add( "jet-booking/calendar/config", modifyBookingConfig );
<?php
function getQueryResult($query_id = 1){
if(function_exists('jet_engine')){
$query = Jet_Engine\Query_Builder\Manager::instance()->get_query_by_id( $query_id );
return $query ? ',' . jet_engine()->listings->macros->do_macros('%query_results|' . $query_id . '|ids%') . ',' : '';
@LaxusCroco
LaxusCroco / macros_in_default_value.php
Created November 17, 2023 16:20
Use macros of JetEngine in the Default Value area of Hidden, Text, Date, Time, Datetime, Colorpicker, and Number fields.
<?php
class JFB_Do_Macros_In_Default {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'maybe_add_filter' ) );
}
public function maybe_add_filter() {
if ( ! function_exists( 'jet_engine' ) ) {
@LaxusCroco
LaxusCroco / search_terms_by_names.php
Created November 21, 2023 10:50
Insert '_search_by_term_name' into the Query Variable of the Search Filter to search the taxonomy listing by term names. Apply a Terms Query to the listing
<?php
add_filter( 'jet-smart-filters/query/final-query', function($query){
if( isset( $query['meta_query'] ) ){
foreach( $query['meta_query'] as $item => $value){
if( $value['key'] === '_search_by_term_name' ){
@LaxusCroco
LaxusCroco / media-file-name-in-global-macros.html
Created November 27, 2023 10:48
Display the uploaded Media file name with global macros of JetFormBuilder. Replace s_cv with the Media field name and uploaded_cv with an element ID, under which the Media field name should be shown
<script>
document.addEventListener('DOMContentLoaded', function () {
const fileInput = document.querySelector('#s_cv');
const outputPara = document.querySelector('#uploaded_cv');
fileInput.addEventListener('change', function () {
if (this.files.length > 0) {
let fileNames = Array.from(this.files).map(file => file.name).join(', ');
outputPara.innerHTML = '<b>Uploaded CVs:</b> ' + fileNames;
<style>
.jet-ajax-search__categories-select-icon {
font-family: "Font Awesome 5 Free";
font-weight: 900;
font-size: 14px !important;
font-style: normal;
}
.jet-ajax-search__categories-select-icon svg {
display: none;
@LaxusCroco
LaxusCroco / is-sticky.php
Created November 28, 2023 12:27
Returns 1 if post is sticky
<?php
add_action( 'jet-engine/register-macros', function(){
class Is_Sticky extends \Jet_Engine_Base_Macros {
public function macros_tag() {
return 'is_sticky';
}
@LaxusCroco
LaxusCroco / additional-parameters-for-stripe-gateway.php
Last active December 18, 2024 22:34
This code sets the payment name to the value of the Text form field
<?php
add_action(
'jet-form-builder/gateways/before-create',
function ( $request ) {
if (
// execute this action only when paying through Stripe
! is_a(
$request,
\Jet_FB_Stripe_Gateway\Compatibility\Jet_Form_Builder\Actions\Create_Checkout_Session::class