Skip to content

Instantly share code, notes, and snippets.

@yeriepiscesa
Created April 22, 2019 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeriepiscesa/cf03a129e34f955554cd0ae45cc4762b to your computer and use it in GitHub Desktop.
Save yeriepiscesa/cf03a129e34f955554cd0ae45cc4762b to your computer and use it in GitHub Desktop.
<?php
class SP_Ajax_Administrative_Action extends WP_AJAX {
protected $action = 'administrative-action';
protected function run() {
if( isset( $_GET[ 'province' ] ) && $_GET[ 'province' ] != '' ) {
$prov = trim( $_GET['province'] );
$remote = wp_remote_get( RAJAONGKIR_BASE_URI . '/city?province=' . $prov, array(
'headers' => array( 'key' => RAJAONGKIR_API_KEY )
) );
$data = array();
if( $remote['response']['code'] == 200 ) {
$remote_body = json_decode( $remote['body'] );
$rows = $remote_body->rajaongkir->results;
foreach( $rows as $row ) {
$data[ $row->city_id ] = trim( $row->type . " " . $row->city_name );
}
}
echo json_encode( $data, true );
}
}
}
SP_Ajax_Administrative_Action::listen();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment