Last active
December 21, 2023 13:22
-
-
Save ihslimn/49f2a7fa2cbcbd31820cb38e0cf74d9c to your computer and use it in GitHub Desktop.
JetFormBuilder Update Field addon - custom callback
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 | |
function jfb_tour_get_data( $field_name, $form_id, $form_fields ) { | |
$args = array( | |
'tour_id' => $form_fields['tour_id'] ?? '', | |
'number_of_guests' => $form_fields['number_of_guests'] ?? '', | |
'date' => $form_fields['date'] ?? '', | |
); | |
$url = add_query_arg( $args, 'some URL' ); | |
$response = wp_remote_get( $url ); | |
if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { | |
return ''; | |
} | |
$json = wp_remote_retrieve_body( $response ); | |
if ( empty( $json ) ) { | |
return array(); | |
} | |
$data = json_decode( wp_specialchars_decode( stripcslashes( $json ), ENT_COMPAT ) ); | |
if ( empty( $data ) ) { | |
return array(); | |
} | |
return $data; | |
} | |
function jfb_tour_get_price( $field_name, $form_id, $form_fields ) { | |
$data = jfb_tour_get_data( $field_name, $form_id, $form_fields ); | |
if ( empty( $data ) ) { | |
return 0; | |
} | |
return $data->price ?? 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment