Created
May 16, 2024 13:34
-
-
Save ihslimn/1ac1f09b9990b31962aad727b331a682 to your computer and use it in GitHub Desktop.
Jet_Appointment_Add_Current_Link
This file contains 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 | |
class Jet_Appointment_Add_Current_Link { | |
private $query_var = 'jet_apb_add_current_to_calendar'; | |
public function __construct() { | |
add_action( 'plugins_loaded', array( $this, 'add_filters' ), 1000 ); | |
} | |
public function add_filters() { | |
if ( ! function_exists( 'jet_apb' ) ) { | |
return; | |
} | |
add_filter( 'jet-engine/elementor-view/dynamic-link/generel-options', array( $this, 'register_dynamic_link_option' ) ); | |
add_filter( 'jet-engine/listings/dynamic-link/pre-render-link', array( $this, 'set_html_format_for_render' ), 10, 4 ); | |
} | |
public function register_dynamic_link_option( $options ) { | |
$options[ $this->query_var ] = 'Jet Appointments Booking: add current booking to Google calendar'; | |
return $options; | |
} | |
public function set_html_format_for_render( $pre_render_link, $settings, $base_class, $dynamic_link_class_instance ) { | |
if ( empty( $settings['dynamic_link_source'] ) || $this->query_var !== $settings['dynamic_link_source'] ) { | |
return $pre_render_link; | |
} | |
$object_context = ! empty( $settings['object_context'] ) ? $settings['object_context'] : false; | |
$object = jet_engine()->listings->data->get_object_by_context( $object_context ); | |
if ( empty( $object ) ) { | |
$object = jet_engine()->listings->data->get_current_object(); | |
} | |
if ( empty( $object->slot ) || empty( $object->slot_end ) ) { | |
return $pre_render_link; | |
} | |
$appointment = array( | |
'ID' => $object->ID ?? 0, | |
'date' => $object->date ?? 0, | |
'slot' => $object->slot, | |
'slot_end' => $object->slot_end, | |
'service' => $object->service ?? 0, | |
'provider' => $object->provider ?? 0, | |
); | |
return jet_apb()->google_cal->render_link( $appointment, $settings, $base_class, $dynamic_link_class_instance ); | |
} | |
} | |
new Jet_Appointment_Add_Current_Link(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment