Same as last commit, also replaced woocommerce_get_shop_id with wc_get_page_id as...
authorLaury GvR <laury@gaslightmedia.com>
Tue, 23 May 2017 13:49:36 +0000 (09:49 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Tue, 23 May 2017 13:49:36 +0000 (09:49 -0400)
functions.php
lib/menu-walker.php
parts/shop-sidebar.php
sections/front-page.php

index 63cd93c..3e515e7 100644 (file)
@@ -304,22 +304,27 @@ function new_loop_shop_per_page( $cols ) {
   return $cols;
 }
 
-/* Exclude Category from Shop*/
-add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
-function get_subcategory_terms( $terms, $taxonomies, $args ) {
-    $new_terms = array();
-
-    // if a product category and on the shop page
-    if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
-        foreach ( $terms as $key => $term ) {
-            if ( ! in_array( $term->slug, array( 'downloads' ) ) ) {
-                $new_terms[] = $term;
-            }
-        }
-        $terms = $new_terms;
+// Remove category slug from woocommerce shop
+add_action( 'pre_get_posts', 'remove_cat_from_shop_loop' );
+
+function remove_cat_from_shop_loop( $q ) {
+
+    if ( ! $q->is_main_query() ) return;
+    if ( ! $q->is_post_type_archive() ) return;
+
+    if ( ! is_admin() && is_shop() ) {
+
+        $q->set( 'tax_query', array(array(
+            'taxonomy' => 'product_cat',
+            'field' => 'slug',
+            'terms' => array( 'downloads' ), // Change it to the slug you want to hide
+            'operator' => 'NOT IN'
+        )));
+
     }
 
-    return $terms;
+    remove_action( 'pre_get_posts', 'remove_cat_from_shop_loop' );
+
 }
 
 ?>
index 4e1f7a4..cc9cfee 100644 (file)
@@ -50,7 +50,7 @@ class Glm_Theme_Top_Bar_Walker extends Walker_Nav_Menu {
             $output .= "\n<li>\n";
             $output .= "\n<div class=\"shop-drop\">\n";
             $output .= "\n<h1>Trail Maps & Guidebooks</h1>\n";
-            $output .= "\n<a class=\"button\" href=\"" . get_permalink( woocommerce_get_page_id( 'shop' ) ) . "\">Shop Now</a>\n";
+            $output .= "\n<a class=\"button\" href=\"" . get_permalink( wc_get_page_id( 'shop' ) ) . "\">Shop Now</a>\n";
             $output .="\n</div>\n";
             $output .="\n</li>\n";
         }
index 3ee7ce5..de792a4 100644 (file)
@@ -1,9 +1,9 @@
-<?php 
+<?php
     global $woocommerce;
-?> 
+?>
 <div class="shop-sidebar">
     <div class="page_item page_item_has_children">
-        <a href="<?php echo get_permalink( woocommerce_get_page_id( 'shop' ) ); ?>">
+        <a href="<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?>">
             Categories
         </a>
     </div>
@@ -18,9 +18,9 @@
             Checkout
         </a>
     </div>
-    <?php 
+    <?php
         $myaccount_page_id = get_option( 'woocommerce_myaccount_page_id' );
-        if ( $myaccount_page_id ) { 
+        if ( $myaccount_page_id ) {
             $myaccount_page_url = get_permalink( $myaccount_page_id );
     ?>
     <div class="page_item page_item_has_children">
index 0cea148..16299b8 100644 (file)
@@ -11,7 +11,7 @@
                                     <h4>Shop Our Trail Maps & Guidebooks</h4>
                                     <img class="right" src="<?php echo bloginfo('template_url'); ?>/assets/the-trails-of-m-22-book.png">
                                     <p>Need a good trail map or a guidebook to what lies beyond the pavement? Check out our shop stocked with our latest backpacking maps and books personally autographed by the authors who wrote them! It's the best and most affordable way to purchase maps and trail books to Michigan.</p>
-                                    <a class="button" href="<?php echo get_permalink( woocommerce_get_page_id( 'shop' ) ); ?> ">Shop Now</a>
+                                    <a class="button" href="<?php echo get_permalink( wc_get_page_id( 'shop' ) ); ?> ">Shop Now</a>
                                 </div>
                                 <div class="small-12 large-5 columns">
                                     <div class="blog">