i want get Country Code , State Code, city name, by ip address
You can use third party services like https://www.ip2location.com which will provide you all details you require. you have to call rest api of such services and that service will return data to you
You can use this API to get information like country_code,country_name, region_code,region_name, city,zipcode,latitude, longitude,metro_code,areacode
$location = file_get_contents('http://freegeoip.net/json/'.$_SERVER['REMOTE_ADDR']);
print_r($location);
{ "ip": "77.99.179.98",
"country_code": "GB",
"country_name": "United Kingdom",
"region_code": "H9",
"region_name": "London, City of",
"city": "London",
"zipcode": "",
"latitude": 51.5142,
"longitude": -0.0931,
"metro_code": "",
"areacode": "" }
Related
I have been trying to build a custom Woocommerce Cart API endpoint, I implemented the add to cart feature but I have ended up facing an issue with shipping taxes.
I want to calculate shipping taxes (especially for flexible_shipping_single) but my code isn't working :
$shippings = [];
if (isset($request["shipping_lines"]) && !empty($request["shipping_lines"])) {
foreach ($request["shipping_lines"] as $shipping_line) {
$shippings[] = $shipping_line["method_id"];
}
WC()->session->set('chosen_shipping_methods', $shippings);
}
$cart->calculate_totals();
Here's my request (I removed some lines to minimize the size)
{
"line_items": [
{
"product_id": 15071,
"variation_id": 0,
"quantity": 9
}
],
"shipping": {
"first_name": "John",
"last_name": "Doe",
"address_1": "969 Market",
"address_2": "",
"city": "San Francisco",
"state": "CA",
"postcode": "94103",
"country": "US"
},
"shipping_lines": [
{
"method_id": "flexible_shipping_single",
"method_title": "Flexible Shipping"
}
]
}
The issue:
The issue was in the param "state": CA that doesn't exist in the state's list of the shipping zones, So the calculate_shipping() couldn't find the shipping package related to the shipping method selected by the user and its rates, which means that the flexible_shipping_single won't work, instead, it sets back the default shipping method, in my case wc_pickup_store
Is there any API or anything which provides city,state and country name when pincode is given.Please share if you have any solution
Thanks in Advance
Hello. there are many more sites which provides this kind of
information i will show you two of them.
Third Party API
Google API
try this url with your pincode. this will gives you data in json format like below one. i have removed some of data to show you so it was not exactly as per return response of third party api.
{
"Message": "Number of Post office(s) found: 1",
"Status": "Success",
"PostOffice": [
{
"Name": "I E Bapunagar",
"Description": "",
"BranchType": "Sub Post Office",
"DeliveryStatus": "Delivery",
"Taluk": "Ahmadabad City",
"Circle": "Ahmadabad City",
"District": "Ahmedabad",
"Division": "Ahmedabad City",
"Region": "Ahmedabad HQ",
"State": "Gujarat",
"Country": "India"
}
]
}
check it, and if you want any help,you can ask.
Use the GeoCoding API
For example, to lookup zip 626134 use a request like this:
http://maps.googleapis.com/maps/api/geocode/json?address=626134&sensor=true
Here is the code:
$.getJSON( base_url + '/ajax/sortListings.php', { sort: sort }, function( data ) {
$.each(data, function(i, json) {
$( '#listings' ).append($('<div>').load( base_url + '/partialviews/listingAdminPrev.php', {
id: json.id,
name: json.name,
logo: encodeURIComponent(json.logo),
address: json.address,
city: json.city,
state: json.state,
zip: json.zip,
phone: json.phone,
email: json.email,
web_link: encodeURIComponent(json.web_link),
services: json.services,
category: json.category,
status: json.status,
created: json.created
} ));
});
});
When I manually go to the sortListings.php file and turn the $_POST variables to $_GET, it works fine. So nothing is wrong with the file. But here it is anyway:
include_once('../../app/scripts/config.php');
$listingObject = Listing::getInstance();
$results = $listingObject->get_listings($_POST['sort']);
echo json_encode($results);
That file returns this:
[
{
"id": "32",
"user_id": "32",
"logo": "32_52a0960ba791c.jpg",
"name": "Anthony Thomas Advertising",
"address": "380 S. Main St.",
"city": "Akron",
"state": "AL",
"zip": "44311",
"phone": "3302536888",
"email": "wayne#anthonythomas.com",
"web_link": "http://www.aol.com",
"status": "1",
"services": "dfhfdhdfh",
"category": "1",
"created": "2013-12-05 09:32:56"
},
{
"id": "20",
"user_id": "10",
"logo": "10_529f96001390d.png",
"name": "Graphic Installation Services",
"address": "2808 Broadway Blvd Unit 1",
"city": "Monroeville",
"state": "PA",
"zip": "15146",
"phone": "3306599898",
"email": "graphic#graphicinstallationservices.com",
"web_link": "",
"status": "4",
"services": "Graphic installation services",
"category": "1",
"created": "2013-12-04 11:35:11"
},
{
"id": "21",
"user_id": "10",
"logo": "10_529f9c1a8375d.png",
"name": "Intellect Productions",
"address": "2915 13th St NW",
"city": "Canton",
"state": "OH",
"zip": "44708",
"phone": "3309334833",
"email": "mouseywings#live.com",
"web_link": "",
"status": "1",
"services": "Car Wrap Installations by Intellect Productions",
"category": "1",
"created": "2013-12-04 15:20:15"
},
{
"id": "19",
"user_id": "10",
"logo": "10_529cf170b08d7.png",
"name": "International Installations Inc",
"address": "833 Wooster Rd N",
"city": "Barberton",
"state": "OH",
"zip": "44203",
"phone": "3306586526",
"email": "internationalinstallers#internationinstallers.com",
"web_link": "http://intellectproductions.com/",
"status": "1",
"services": "We install:\r\n· vehicle wraps\r\n· decals\r\n· vehicle lettering\r\n· banners\r\n· billboards\r\n· murals\r\nInternational Image Application Inc. is PDAA certified. We strive to deliver a constant flow of high quality work using best materials in the business, and unsurpassed skill. This ensures that our clients receive value for money, and more bang for their buck!\r\nAnd to ensure that our clients continue to receive the highest quality of work possible, we stay on top of technological trends, new materials, and installation techniques. This dedication to continued education has resulted in many clients coming back again and again.\r\nFrom a simple vehicle wraps installation to an entire ad campaign or fleet, International Image Application Inc. is your destination for precision graphics installation on virtually any medium.",
"category": "1",
"created": "2013-12-04 10:32:52"
}
]
Which is 5 listings.. so it's pulling the data fine. However, nothing is working beyond the $.each().. I even tried alerting stuff and nothing.
No console errors are thrown either..
You hit on your problem. You are expecting the sort parameter in $_POST while you are calling getJSON() which executes a GET.
Make up your mind whether you want to use GET or POST and be consistent.
My guess is you also need to put better error handling in Listing::get_listings() method to provide useful errors when you are not getting the data your expect passed to it.
When i create an event with the graph api i need to specify the venue and i would like also to show the map.
I do
$fb_event['name'] = "THis is to test latitude";
$fb_event['description'] = "And longitude!!!!";
$fb_event['start_time'] = date( "c", Ai1ec_Facebook_Event::get_facebook_start_time($event->start));
$fb_event['location'] = "Where you want";
$fb_event['street'] = "Via andrea del sarto 9";
$fb_event['city'] = "Milan";
$fb_event['latitude'] = 45.444975793404;
$fb_event['longitude'] = 9.2119209654715;
$facebook = $this->facebook_instance_factory();
try {
$result = $facebook->api( "/me/events", "POST", $fb_event );
} catch (FacebookApiException $e) {
fb($e);
}
This produce this event which show the correct street and city, but no map. If i edit the event and save, the map "Magically" appears using the street and city correctly.
In any case latitude and longitude are ignored.
What am i doing wrong?
If you compare your two test events in the Graph API explorer you'll see that Event ID 239298922846828 does not have its latitude and longitude populated, while 245655182207213 does. I'm assuming 245655182207213 is an event you've edited.
Looking at your code, you seem to be doing everything as described in the documentation. However, I've found that what is described does not always work.
What I've been seeing is that events populated from within Facebook that occur at a known venue are no longer allowing you to specify an address. Instead all they save is a venue id within Facebook which you can then drill into to get the address, etc.
Take a look at one of my events. For this event, there is no way to edit the details of this location from within Facebook, nor does the event venue details get returned with an API call. I'm using the API to pull the event details to an external website. This change caused me days of frustration.
I started seeing this behavior in late April. I haven't found any official documentation announcing this change.
When some documentation appears, what I expect the new event venue workflow will be is something like:
Query the area where your event will take place to see if a venue exists already.
If yes, get save its id.
If not, create a new community page for your venue and save its id.
Use this ID to populate the event venue.
In the end this is a known facebook bug
https://developers.facebook.com/bugs/173095916131752
Two different formats when create using the same parameters.
When create event through gql
{
"id": "xxxxxxxxxxxxxx",
"owner": {
"name": "xxxxxxxxxx",
"id": "xxxxxxxxx"
},
"name": "W1112",
"start_time": "2013-10-22",
"is_date_only": true,
"location": "Tulsa, OK, United States",
"venue": {
"latitude": 36.131388888889,
"longitude": -95.937222222222,
"street": "",
"zip": "",
"id": "109436565740998"
},
"privacy": "SECRET",
"updated_time": "2013-09-19T12:23:26+0000"
}
When create event through fb
{
"id": "xxxxxxxxxxxxxx",
"owner": {
"name": "xxxxxx",
"id": "xxxxxxxx"
},
"name": "1234",
"start_time": "2013-10-09T21:26:00+1100",
"end_time": "2013-10-25T00:26:00+1100",
"timezone": "Australia/Sydney",
"is_date_only": false,
"location": "Maroubra Junction",
"venue": {
"latitude": -33.940804216453,
"longitude": 151.23876752992,
"city": "Maroubra",
"state": "NSW",
"country": "Australia",
"id": "153993547968514",
"street": "832 anzac Parade ",
"zip": "2035"
},
"privacy": "SECRET",
"updated_time": "2013-09-19T10:50:14+0000"
}
I'm using UPS api(JSON) refer from the ups.com developer kit.
1)I need shipment rating list with "Residential Shipment".
2)I need Add shipment with "Residential Address".
I am add ResidentialAddressIndicator as 1 in ShipTo address.(I am refer from UPS doc.)
But it's failed.
2)Sample code:
...........
...........
"ShipTo": {
"Name": "Ship To Name",
"AttentionName": "Ship To Attn Name",
"Phone": {
"Number": "1234567890"
},
"Address": {
"AddressLine": "195 N main st",
"City": "Sebastopol",
"StateProvinceCode": "CA",
"PostalCode": "95472",
"CountryCode": "US",
"ResidentialAddressIndicator":"1" //I am refer from UPS doc.
}
},
..........
..........
Your answers are highly appreciated!
in the <ShipTo> element add <Residential Address/>, you can find this in the Shipping Package XML Developers Guide that UPS provides.