Created
June 25, 2013 20:26
Revisions
-
dustyf created this gist
Jun 25, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,54 @@ <?php function displayLocationDropdown() { $html = ''; $html .= '<form class="location-select" method="post">'; $html .= '<select id="location-selector" name="location" class="location">'; $tag = wp_tag_cloud( array( 'format' => 'array', 'taxonomy' => 'product_tag' ) ); $page_path = $_SERVER["REQUEST_URI"]; $page_url = site_url() . $page_path; $url_parts = parse_url($page_url); $constructed_url = $url_parts['scheme'] . '://' . $url_parts['host'] . (isset($url_parts['path'])?$url_parts['path']:''); $html .= '<option value="#">--Select Location--</option>'; foreach($tag as $tagkey => $tagvalue) { $cleanedup = strip_tags($tagvalue); $tag_info = get_term_by('name', $cleanedup, 'product_tag', 'ARRAY_A'); $tag_slug = $tag_info['slug']; if(isset($_GET['product_tag'])) { $value_url = $constructed_url . '?product_tag=' . $tag_slug; } else { $value_url = $page_url . '?product_tag=' . $tag_slug; } $html .= '<option value="' . $value_url . '">' . $cleanedup . '</option>'; } $html .= '<option value="' . $constructed_url . '">View All Locations</option>'; $html .= '</select>'; $html .= '</form>'; echo $html; } add_action('woocommerce_before_shop_loop', 'displayLocationDropdown', 40); add_action('wp_head', 'addDisplayLocationScript'); function addDisplayLocationScript() { $script = ''; $script .= '<script type="text/javascript">'; $script .= 'jQuery(document).ready(function() {'; $script .= ' jQuery("#location-selector").change(function() {'; $script .= ' location = jQuery("#location-selector option:selected").val();'; $script .= ' });'; $script .= '});'; $script .= '</script>'; echo $script; }