{"id":4299,"date":"2020-03-25T16:45:43","date_gmt":"2020-03-25T05:45:43","guid":{"rendered":"https:\/\/wpdevdesign.wpengine.com\/?p=4299"},"modified":"2020-03-25T16:45:45","modified_gmt":"2020-03-25T05:45:45","slug":"condition-us-state","status":"publish","type":"post","link":"https:\/\/wpdevdesign.com\/condition-us-state\/","title":{"rendered":"[Condition] US State"},"content":{"rendered":"<div class=\"mp_wrapper\">\n  <div class=\"mepr-unauthorized-excerpt\">\n    <p>This <a aria-label=\" (opens in a new tab)\" href=\"https:\/\/wpdevdesign.com\/membership\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">members-only<\/a> tutorial provides the steps to register a custom <a aria-label=\"Oxygen (opens in a new tab)\" href=\"https:\/\/oxygenbuilder.com\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Oxygen<\/a> condition using which elements can be output to users visiting from a specific state in the US using the API from <a href=\"https:\/\/ipapi.co\/\" target=\"_blank\" aria-label=\"ipapi.co (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">ipapi.co<\/a>.<\/p>\n<figure class=\"wp-block-image size-large\"><img src=\"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2020\/03\/oxygen-condition-us-state-1024x567.png\" alt=\"\" class=\"wp-image-4300\" \/><\/figure>\n<p>We are going to add \"US State\" in the conditions list under the \"Other\" category with equals and not equals operators.<\/p>\n<p>Meaning, you can either output or NOT output any element in the Oxygen builder to visitors from a specific US state.<\/p>\n<p>Note: You can easily modify this to check against regions (states) of any country by replacing the state names in the code.<\/p>\n<h4 class=\"wp-block-heading\">Use Case<\/h4>\n<p>Say you own a tours attraction website based in the US. You could show one Section for visitors from New York and another for visitors from a different state say, Florida.<\/p>\n<p>Note that the great thing about Oxygen's conditions is that content gets output or printed on the front end conditionally and it is not that it is just hidden or shown using CSS\u2019 display property.<\/p>\n<h4 class=\"wp-block-heading\">Caveat<\/h4>\n<p>IP and State detection may not work reliably when there is caching (especially at\u00a0the server\u00a0level) involved. You may need to add the page(s) where you are implementing this to your cache plugin's exclusion list.<\/p>\n<p>You are advised to test this solution first before using it in production.<\/p>\n<h3 class=\"wp-block-heading\">Step 1<\/h3>\n<p>Install and activate <a href=\"https:\/\/wordpress.org\/plugins\/code-snippets\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"rank-math-link\">Code Snippets<\/a> plugin.<\/p>\n<p>Go to Snippets &gt; Add New.<\/p>\n<p>Title: <strong>[Function] Get IP Address<\/strong><\/p>\n<p>Code:<\/p>\n  <\/div>\n  <div class=\"mepr-unauthorized-message\">\n    <p>This is a premium members-only content.<\/p>\n<p>To view the rest of the content, please <a title=\"Membership\" href=\"https:\/\/wpdevdesign.com\/membership\/\">sign up for membership ($47\/month or $599 one-time)<\/a>.<\/p>\n<p>Already a member? Log in below or <a href=\"https:\/\/wpdevdesign.com\/login\/\">here<\/a>.<\/p>\n  <\/div>\n  <div class=\"mepr-login-form-wrap\">\n            \n<div class=\"mp_wrapper mp_login_form\">\n                  <!-- mp-login-form-start -->     <form name=\"mepr_loginform\" id=\"mepr_loginform\" class=\"mepr-form\" action=\"https:\/\/wpdevdesign.com\/login\/\" method=\"post\">\n            <div class=\"mp-form-row mepr_username\">\n        <div class=\"mp-form-label\">\n                              <label for=\"user_login\">Username<\/label>\n        <\/div>\n        <input type=\"text\" name=\"log\" id=\"user_login\" value=\"\" \/>\n      <\/div>\n      <div class=\"mp-form-row mepr_password\">\n        <div class=\"mp-form-label\">\n          <label for=\"user_pass\">Password<\/label>\n          <div class=\"mp-hide-pw\">\n            <input type=\"password\" name=\"pwd\" id=\"user_pass\" value=\"\" \/>\n            <button type=\"button\" class=\"button mp-hide-pw hide-if-no-js\" data-toggle=\"0\" aria-label=\"Show password\">\n              <span class=\"dashicons dashicons-visibility\" aria-hidden=\"true\"><\/span>\n            <\/button>\n          <\/div>\n        <\/div>\n      <\/div>\n            <div>\n        <label><input name=\"rememberme\" type=\"checkbox\" id=\"rememberme\" value=\"forever\" \/> Remember Me<\/label>\n      <\/div>\n      <div class=\"mp-spacer\">&nbsp;<\/div>\n      <div class=\"submit\">\n        <input type=\"submit\" name=\"wp-submit\" id=\"wp-submit\" class=\"button-primary mepr-share-button \" value=\"Log In\" \/>\n        <input type=\"hidden\" name=\"redirect_to\" value=\"\/wp-json\/wp\/v2\/posts\/4299\" \/>\n        <input type=\"hidden\" name=\"mepr_process_login_form\" value=\"true\" \/>\n        <input type=\"hidden\" name=\"mepr_is_login_page\" value=\"false\" \/>\n      <\/div>\n    <\/form>\n    <div class=\"mp-spacer\">&nbsp;<\/div>\n    <div class=\"mepr-login-actions\">\n        <a\n          href=\"https:\/\/wpdevdesign.com\/login\/?action=forgot_password\"\n          title=\"Click here to reset your password\"\n        >\n          Forgot Password        <\/a>\n    <\/div>\n\n      \n    <!-- mp-login-form-end --> \n  <\/div>\n      <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This members-only tutorial provides the steps to register a custom Oxygen condition using which elements can be output to users visiting from a specific state in the US using the API from ipapi.co. We are going to add &#8220;US State&#8221; in the conditions list under the &#8220;Other&#8221; category with equals and not equals operators. Meaning, &hellip;<\/p>\n","protected":false},"author":1,"featured_media":4301,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"footnotes":""},"categories":[64,52],"tags":[315,187,316],"class_list":["post-4299","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oxygen","category-premium","tag-api","tag-conditions","tag-ip"],"acf":[],"featured_image_src":"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2020\/03\/oxygen-condition-us-state-featured-image.png","featured_image_src_square":"https:\/\/wpdevdesign.com\/wp-content\/uploads\/2020\/03\/oxygen-condition-us-state-featured-image.png","author_info":{"display_name":"Sridhar Katakam","author_link":"https:\/\/wpdevdesign.com\/author\/srikat\/"},"_links":{"self":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts\/4299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/comments?post=4299"}],"version-history":[{"count":0,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/posts\/4299\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/media\/4301"}],"wp:attachment":[{"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/media?parent=4299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/categories?post=4299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpdevdesign.com\/wp-json\/wp\/v2\/tags?post=4299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}