get current visitor country code in shopify liquid file - shopify

how I get current visitor country code in shopify liquid file?
{{ localization.country.iso_code }}
I use this code but not working. it's always get store location country code.

I know a way to get the country but not the code.
Let's assume you have an HTML element in some page that you want to display the country name inside
<p class="visitor-country-name"></p>
First install the free app (made by Shopify) called Geolocation.
Then put this JS code somewhere in that page inside < script > tags
fetch('browsing_context_suggestions.json')
.then(res=>res.json())
.then(r=> document.querySelector(".blog__title.h1").innerHTML = r.detected_values.country.name)
This will get the json file containing the visitor information, extract the 'detected_values.country.name' value from it, and inject it to the HTML element 'p' with the class name 'visitor-country-name'.
To see all available information visit the url below (replace 'store-name' with your store name)
store-name.myshopify.com/browsing_context_suggestions.json

Related

Google Custom Search Engine - Edit the URLs in SERP

Good evening, I'm working with Google Custom Search Engine: https://cse.google.it/cse/ and I need to add, only for some URLs (in total 10 URLs) a parameter at the end of each search results URL. For example: if the domain is www.dominio-test.com then the URL to show is www.dominio-test.com/123456 the CSE searches on the web without restriction.
The code I use is the following:
<script async src = "https://cse.google.com/cse.js cx=014431187084467459449:v2cmjgvgjr0"> </script>
<div class = "gcse-search"> </div>
I thought of proceeding with reading the DOM with getElementsByClassName (), extracting the content and adding it to a variable, at this point add the if / else / replace controls and output again.
But I don't know how to proceed, can you please support me?
Thanks and good job
Search Element callbacks might work for you: https://developers.google.com/custom-search/docs/element#callbacks

How to get User Data from account.html page? - BigCommerce

I'm planning to render a page from my private app by passing user id using an iframe. To do that, I need to fetch logged in user's id. How can I get that?
I tried the following options, other than for GLOBAL_StoreName, nothing comes up.
<h3>%%GLOBAL_AccountPhone%%</h3>
<h3>%%GLOBAL_AccountFirstName%%</h3>
<h2>%%GLOBAL_StoreName%%</h2>
<h2>%%GLOBAL_CustomerId%%</h2>
<h2>%%GLOBAL_CustomerEmail%%</h2>
<h2>%%GLOBAL_CustomerPhone%%</h2>
I'm planning to pass the info through an iframe in the src url.
<iframe src="https://custom-app.herokuapp.com/account?id=<ID>" width="100%" height="1000px" frameborder="0"></iframe>
Update
I was able to get current customer first name and last name, but not the Id.
%%GLOBAL_CurrentCustomerFirstName%%
%% GLOBAL_CurrentCustomerLastName%%
{{customer.id}} should return the ID of the logged in customer on a Stencil theme, but for Blueprint (legacy) themes, there is not a storewide global variable that will return the customer ID. %%GLOBAL_CustomerId%% is only invoked in the template file for the form to reset the customer's password.
As an alternative, your app can use the Current Customer API to return the current customer's ID, email, and customer group:
https://developer.bigcommerce.com/api/#current-customer-api

Extract portion of HTML from website?

I'm trying to use VBA in Excel, to navigate a site with Internet explorer, to download an Excel file for each day.
After looking through the HTML code of the site, it looks like each day's page has a similar structure, but there's a portion of the website link that seems completely random. But this completely random part stays constant and does not change each time you want to load the page.
The following portion of the HTML code contains the unique string:
<a href="#" onClick="showZoomIn('222698519','b1a9134c02c5db3c79e649b7adf8982d', event);return false;
The part starting with "b1a" is what is used in the website link. Is there any way to extract this part of the page and assign it as a variable that I then can use to build my website link?
Since you don't show your code, I will talk too in general terms:
1) You get all the elements of type link (<a>) with a Set allLinks = ie.document.getElementsByTagName("a"). It will be a vector of length n containing all the links you scraped from the document.
2) You detect the precise link containing the information you want. Let's imagine it's the 4th one (you can parse the properties to check which one it is, in case it's dynamic):
Set myLink = allLinks(3) '<- 4th : index = 3 (starts from zero)
3) You get your token with a simple split function:
myToken = Split(myLink.onClick, "'")(3)
Of course you can be more synthetic if the position of your link containing the token is always the same, like always the 4th link:
myToken = Split(ie.document.getElementsByTagName("a")(3).onClick,"'")(3)

Netsuite PDF Templating: get number of pages as attribute

I am templating pdfs in Netsuite using freemarker and I want to display the footer only on the last page. I have been doing some research, but couldn't find a solution (since looks like the environment does not allow me to include or import libs), so I thought that just comparing the number of the page with the total pages in an if tag would be a nice and easy workaround. I already know how to display the numbers by using the <pagenumber/> and <totalpages/> tags, but still cannot get them as values so I can use them like this:
<#if (pagenumber == totalpages) >
... footer html...
</#if>
Any ideas of how or where can I get those values from?
The approach you are trying won't work, because you are mixing BFO and Freemarker syntax. Netsuite uses two different "engines" to process PDF Templates. The first step is Freemarker, which merges the record fields with your template and produces an XML file, which is then converted by BFO into a PDF file. The <totalpages/> element is meaningless to Freemarker, as it is only converted into a number by BFO later.
Unfortunately, the ability to add a footer to only the last page of a document is currently a limitation of BFO, as per the BFO FAQ:
At the moment we do not have a facility for explicitly assigning a
footer or header to the last page in a document when the number of
pages is unknown.
You CAN add it after a page break - and put the page break at the end of the body
<pbr footer="nlfooter" footer-height="25%"></pbr>
</body>
The issue here is - on a one page output - you will get 2 pages minimum... it will always ADD a page for the disclaimer / footer...

Custom meta title on checkout/success page in opencart

I am new to opencart and need help with oc 1.5.5.1
I am trying to call custom meta title to add last order id on checkout/success page. I have followed a very helpfull response from shadyyx on Opencart successful order ID and Total from JavaScript
Now I am stuck at a point on how to use the order_id which is already available in session and call / display it in meta title of checkout/success page.
As I understood you, you need to check if the orderid exists and not empty and route is checkout/success so for example add this to $this->data['my-new-metatag']
All above do in the common/header controller (cos meta tags are in the common/header tpl file)
then in common/header.tpl check if $my-new-metatag exists, echo it, otherwise leave variable that echos by default