auto-update-appointment-provider.php
2 months ago
auto-update-appointment-service.php
2 months ago
auto-update-field-value.php
2 months ago
base-field-context-macro.php
2 months ago
auto-update-appointment-service.php
77 lines
| 1 | <?php |
| 2 | /** |
| 3 | * JetAppointment service macro for JetFormBuilder auto-update. |
| 4 | * |
| 5 | * @package JFB_Compatibility\Jet_Engine\Macros |
| 6 | */ |
| 7 | |
| 8 | namespace JFB_Compatibility\Jet_Engine\Macros; |
| 9 | |
| 10 | if ( ! defined( 'WPINC' ) ) { |
| 11 | die; |
| 12 | } |
| 13 | |
| 14 | class Auto_Update_Appointment_Service extends Base_Field_Context_Macro { |
| 15 | |
| 16 | public function macros_tag() { |
| 17 | return 'jfb_auto_update_appointment_service'; |
| 18 | } |
| 19 | |
| 20 | public function macros_name() { |
| 21 | return 'JFB Auto-Update - JetAppointment Service'; |
| 22 | } |
| 23 | |
| 24 | public function macros_args() { |
| 25 | return array( |
| 26 | 'field_name' => array( |
| 27 | 'label' => __( 'Field Name', 'jet-form-builder' ), |
| 28 | 'type' => 'text', |
| 29 | 'default' => '', |
| 30 | ), |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | public function macros_callback( $args = array() ) { |
| 35 | $field_name = ! empty( $args['field_name'] ) ? $args['field_name'] : null; |
| 36 | |
| 37 | if ( ! $field_name || ! function_exists( 'jet_apb' ) || ! function_exists( 'jet_engine' ) ) { |
| 38 | return ''; |
| 39 | } |
| 40 | |
| 41 | $post_id = $this->get_context_value( $field_name ); |
| 42 | |
| 43 | if ( ! $post_id ) { |
| 44 | return ''; |
| 45 | } |
| 46 | |
| 47 | $post = get_post( $post_id ); |
| 48 | |
| 49 | if ( ! $post ) { |
| 50 | return ''; |
| 51 | } |
| 52 | |
| 53 | $provider_id = $post->ID; |
| 54 | $services_cpt = jet_apb()->settings->get( 'services_cpt' ); |
| 55 | $providers_cpt = jet_apb()->settings->get( 'providers_cpt' ); |
| 56 | |
| 57 | if ( ! $provider_id || ! $services_cpt || ! $providers_cpt ) { |
| 58 | return ''; |
| 59 | } |
| 60 | |
| 61 | $services = jet_engine()->relations->get_related_posts( |
| 62 | array( |
| 63 | 'post_type_1' => $services_cpt, |
| 64 | 'post_type_2' => $providers_cpt, |
| 65 | 'post_id' => $provider_id, |
| 66 | 'from' => $services_cpt, |
| 67 | ) |
| 68 | ); |
| 69 | |
| 70 | if ( ! is_array( $services ) ) { |
| 71 | $services = array( $services ); |
| 72 | } |
| 73 | |
| 74 | return implode( ',', array_filter( $services ) ); |
| 75 | } |
| 76 | } |
| 77 |