add_action('init', function() {
function get_user_by_chat_id(){
$request = json_decode($_GET['meta_data']);
$user = get_users(array('meta_key' => 'chatid', 'meta_value' => (int) $request['chatid']));
if ( empty( $user ) )
return new WP_Error( 'no_users', 'User with this chat id not found', [ 'status' => 404 ] );
return $user;
}
});
add_action( 'rest_api_init', function(){
register_rest_route( 'wc/v3', 'customers2', [
'methods' => 'GET',
'callback' => 'get_user_by_chat_id',
] );
} );
$callback = json_decode(file_get_contents('php://input'), true);
print_r($callback); //Выводит весь колбек
echo $callback['payment']['comment']; //Выводит комменатрий платежа
<script>
function openInNewTab() {
let win = window.open("https://code.patriotovsky.ru/", '_blank');
win.focus();
}
</script>
<form method="POST" action="send.php">
<input name="none" type="text" /><br />
<button class="button" type="submit" name="send-button" onclick="openTab()">КНОПКА</button>
</form>