Last active
November 16, 2017 06:49
-
-
Save sarathlal-old/b601398a4ba04fb3cecf4ee015597b97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ghjut35_script() { | |
| if(is_singular('product')){ | |
| ?> | |
| <script type="text/javascript"> | |
| function QueryStringToJSON() { | |
| var pairs = location.search.slice(1).split('&'); | |
| var result = {}; | |
| pairs.forEach(function(pair) { | |
| pair = pair.split('='); | |
| result[pair[0]] = decodeURIComponent(pair[1] || ''); | |
| }); | |
| return JSON.parse(JSON.stringify(result)); | |
| } | |
| var query_string = QueryStringToJSON(); | |
| //console.log(query_string); | |
| for (var key in query_string) { | |
| if (query_string.hasOwnProperty(key)) { | |
| //console.log(key + " -> " + query_string[key]); | |
| //jQuery("#"+key).find("input").val(query_string[key]); | |
| document.getElementById(key).value = query_string[key]; | |
| } | |
| } | |
| </script> | |
| <?php | |
| } | |
| } | |
| add_action( 'wp_footer', 'ghjut35_script', 100 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment