• Resolved Steve Weigold

    (@sweigold)


    Updated versions of WooCommerce and Storefront. Problem I’m having after update is SOME, not all categories are not displaying as expected. The linked page above is one example. My categories are set to display both subcategories and products, but I have a modification in my child theme because I only want the products displayed for the category being view and not the products of the subcategories. The code for this is below.

    This has worked on all categories up until the 3.3.1 update I believe. Now, it works for many still, but not all. Generally, I find that now in a product category that doesn’t have any products, only subcategories, I get the “no products found” message.

    Things I’ve tried:
    – No caching plugins in use
    – Clearing browser caches, WooCommerce counters etc has no effect
    – On the errant pages, no changes to display settings has any effect
    – If I add a test product to the errant category, the category and subcategories display as expected.
    – If I remove my exclude code below, most pages display with products, subcategories and subcategory products as I would expect, BUT, the errant categories display subcategories, but NOT subcategory products, so are still displaying incorrectly based on settings.

    Help please!
    Steve

    Exclude code:

    
    function exclude_product_cat_children($wp_query) {
    	if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
    		$wp_query->set('tax_query', array(
    				array (
    						'taxonomy' => 'product_cat',
    						'field' => 'slug',
    						'terms' => $wp_query->query_vars['product_cat'],
    						'include_children' => false
    				)
    		)
    		);
    	}
    }
    add_filter('pre_get_posts', 'exclude_product_cat_children');
    
    
    ### WordPress Environment ###
    
    Home URL: https://sbw.weigoldenterprises.com
    Site URL: https://sbw.weigoldenterprises.com
    WC Version: 3.3.1
    Log Directory Writable: ?
    WP Version: 4.9.4
    WP Multisite: –
    WP Memory Limit: 256 MB
    WP Debug Mode: ?
    WP Cron: ?
    Language: en_US
    
    ### Server Environment ###
    
    Server Info: Apache/2.4.10 (Debian)
    PHP Version: 5.6.33-0+deb8u1
    PHP Post Max Size: 8 MB
    PHP Time Limit: 30
    PHP Max Input Vars: 2000
    cURL Version: 7.38.0
    OpenSSL/1.0.1t
    
    SUHOSIN Installed: –
    MySQL Version: ? 5.5.49 - We recommend a minimum MySQL version of 5.6. See: WordPress requirements
    Max Upload Size: 8 MB
    Default Timezone is UTC: ?
    fsockopen/cURL: ?
    SoapClient: ?
    DOMDocument: ?
    GZip: ?
    Multibyte String: ?
    Remote Post: ?
    Remote Get: ?
    
    ### Database ###
    
    WC Database Version: 3.3.1
    WC Database Prefix: wp_
    MaxMind GeoIP Database: ? The MaxMind GeoIP Database does not exist - Geolocation will not function. You can download and install it manually from https://dev.maxmind.com/geoip/legacy/geolite/ to the path: . Scroll down to "Downloads" and download the "Binary / gzip" file next to "GeoLite Country". Please remember to uncompress GeoIP.dat.gz and upload the GeoIP.dat file only.
    Total Database Size: 13.48MB
    Database Data Size: 8.51MB
    Database Index Size: 4.97MB
    wp_woocommerce_sessions: Data: 0.05MB + Index: 0.02MB
    wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.05MB
    wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_order_itemmeta: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB
    wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB
    wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB
    wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB
    wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB
    wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB
    wp_commentmeta: Data: 0.02MB + Index: 0.03MB
    wp_comments: Data: 0.02MB + Index: 0.09MB
    wp_links: Data: 0.02MB + Index: 0.02MB
    wp_mgmlp_folders: Data: 0.00MB + Index: 0.01MB
    wp_options: Data: 3.02MB + Index: 0.11MB
    wp_postmeta: Data: 3.06MB + Index: 3.52MB
    wp_posts: Data: 1.52MB + Index: 0.31MB
    wp_rg_form: Data: 0.02MB + Index: 0.00MB
    wp_rg_form_meta: Data: 0.08MB + Index: 0.00MB
    wp_rg_form_view: Data: 0.02MB + Index: 0.03MB
    wp_rg_incomplete_submissions: Data: 0.02MB + Index: 0.02MB
    wp_rg_lead: Data: 0.02MB + Index: 0.03MB
    wp_rg_lead_detail: Data: 0.02MB + Index: 0.06MB
    wp_rg_lead_detail_long: Data: 0.02MB + Index: 0.00MB
    wp_rg_lead_meta: Data: 0.02MB + Index: 0.05MB
    wp_rg_lead_notes: Data: 0.02MB + Index: 0.03MB
    wp_sentry_groups: Data: 0.02MB + Index: 0.00MB
    wp_termmeta: Data: 0.05MB + Index: 0.03MB
    wp_terms: Data: 0.02MB + Index: 0.03MB
    wp_term_relationships: Data: 0.11MB + Index: 0.08MB
    wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB
    wp_usermeta: Data: 0.02MB + Index: 0.03MB
    wp_users: Data: 0.02MB + Index: 0.05MB
    wp_wc_download_log: Data: 0.02MB + Index: 0.03MB
    wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB
    
    ### Post Type Counts ###
    
    acf-field: 7
    acf-field-group: 3
    attachment: 236
    content_block: 5
    customize_changeset: 8
    mgmlp_media_folder: 71
    nav_menu_item: 46
    page: 13
    post: 3
    product: 762
    product_variation: 252
    revision: 46
    shop_order: 1
    ultimate_slider: 5
    wccpf: 1
    
    ### Security ###
    
    Secure connection (HTTPS): ?Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
    Hide errors from visitors: ?Error messages should not be shown to visitors.
    
    ### Active Plugins (11) ###
    
    Gravity Forms: by rocketgenius – 2.2.5
    Advanced Custom Fields PRO: by Elliot Condon – 5.6.8
    Content Blocks (Custom Post Widget): by Johan van der Wijk – 3.0.3
    WordPress Media Library Folders: by Max Foundry – 4.1.1
    Slider Ultimate: by Etoile Web Design – 1.0.21 – Not tested with the active version of WooCommerce
    Woo Product Images Slider: by DesirePress – 1.3.0 – Not tested with the active version of WooCommerce
    WooCommerce Authorize.Net AIM Gateway: by SkyVerge – 3.12.2 – 3.13.0 is available – Not tested with the active version of WooCommerce
    WooCommerce PayPal Powered by Braintree Gateway: by WooCommerce – 2.1.1
    WooCommerce - Gravity Forms Product Add-Ons: by Lucas Stark – 3.2.5 – 3.2.9 is available – Not tested with the active version of WooCommerce
    WooCommerce - Store Toolkit: by Visser Labs – 1.7.9
    WooCommerce: by Automattic – 3.3.1
    
    ### Settings ###
    
    API Enabled: ?
    Force SSL: –
    Currency: USD ($)
    Currency Position: left
    Thousand Separator: ,
    Decimal Separator: .
    Number of Decimals: 2
    Taxonomies: Product Types: external (external)
    grouped (grouped)
    simple (simple)
    variable (variable)
    
    Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
    exclude-from-search (exclude-from-search)
    featured (featured)
    outofstock (outofstock)
    rated-1 (rated-1)
    rated-2 (rated-2)
    rated-3 (rated-3)
    rated-4 (rated-4)
    rated-5 (rated-5)
    
    ### WC Pages ###
    
    Shop base: #57 - /?page_id=57
    Cart: #7 - /?page_id=7
    Checkout: #2436 - /?page_id=2436
    My account: ? Page ID is set
    but the page does not exist
    
    Terms and conditions: #2438 - /?page_id=2438
    
    ### Theme ###
    
    Name: Storefront Child - SBW Specific
    Version: 1.0.0
    Author URL: https://www.weigoldenterprises.com
    Child Theme: ?
    Parent Theme Name: Storefront
    Parent Theme Version: 2.2.7
    Parent Theme Author URL: https://woocommerce.com/
    WooCommerce Support: ?
    
    ### Templates ###
    
    Overrides: –
    
    ### Templates ###
    
    thumbnail: 
    medium: 
    medium_large: 
    large: 
    woocommerce_thumbnail: 
    woocommerce_single: 
    woocommerce_thumbnail_2x: 
    shop_thumbnail: 
    shop_catalog: 
    shop_single: 
    
    ### Authorize.Net AIM ###
    
    Environment: Test
    Debug Mode: Save to Log
    
    ### Braintree (PayPal) ###
    
    Environment: 
    Tokenization Enabled: –
    Debug Mode: Off
    

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 28 total)
  • Thread Starter Steve Weigold

    (@sweigold)

    Performed an additional test:

    Created a NEW category with no products. Changed one of my existing subcategories to use this as a parent. It too shows the “No products found” message.

    If I add a test product to the new test category, it then displays both the product and the subcategory as I would expect.

    There appears to be a problem with product category display for categories with only subcategories in them.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Struggling to reproduce an issue. I’m not using your snippet, just leaving things default/unaltered.

    Structure:

    – Accessories
    – Hoodies
    – T-shirts

    No products are assigned to Accessories, just the bottom level cats.
    Shop page and cats page are set to show categories.

    I’m able to view accessories and it shows the 2 subcats as normal. The count is the total of products inside all sub categories.

    I am running into the same issue on 3.3.1. Previously, categories that held only subcategories displayed a list of those subcategories. Now, categories that hold only subcategories don’t display any subcategories.

    I’ve tried clearing transients and recounting terms on the Tools page, but that didn’t seem to make a difference.

    I am also seeing the same behavior as @sweigold.

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Best find a way to help me reproduce the issue otherwise I cannot do anything.

    Try to reproduce on a Clean install. No extensions then show me your setup.

    Thread Starter Steve Weigold

    (@sweigold)

    Ick. I was hoping for a better means of diagnosis than spending the time to set up a clean install and then attempt to replicate the problem. I’ll see what I can do. When you say “show me your setup” @mikejolley, I’m assuming you mean the status output?

    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    That and possibly a cut down version of your category setup if it differs greatly than the one I described. Maybe product csv export too?

    Or if you get in touch with the help desk granting access will be helpful if it’s not easy to reproduce.

    For me it’s because of a pre_get_posts filter I wrote to remove subcategory products from displaying in a parent category that is set to display Both.

    Utility Category
    – direct 3 child products
    – 1 Subcategory with a few products
    – pre_get_posts filter was written for this to hide the subcategory’s products from displaying on the main Utility page since we just want the link to display to the subcategory

    Telecom Category
    – no direct products
    – only has 2 subscategories
    – the pre_get_posts is affecting this one negatively. It’s not displaying the subcategories products which is the correct behavior from this filter. But it’s not displaying the 2 subcategory links which is the problem.

    I am only changing the tax_query by adding a NOT IN filter for the subcats.

    array(3) {
      ["relation"]=>
      string(3) "AND"
      [0]=>
      array(4) {
        ["taxonomy"]=>
        string(18) "product_visibility"
        ["field"]=>
        string(16) "term_taxonomy_id"
        ["terms"]=>
        array(1) {
          [0]=>
          int(7)
        }
        ["operator"]=>
        string(6) "NOT IN"
      }
      [1]=>
      array(1) {
        [0]=>
        array(4) {
          ["taxonomy"]=>
          string(11) "product_cat"
          ["field"]=>
          string(2) "id"
          ["terms"]=>
          array(2) {
            [0]=>
            int(170)
            [1]=>
            int(26)
          }
          ["operator"]=>
          string(6) "NOT IN"
        }
      }
    }

    This is the tax_query change for this category page.

    Additionally if I remove my pre_get_posts and do this instead, it still has the same negative effects:

    function exclude_child_products_in_cat($wp_query) {  
            foreach($wp_query->tax_query->queries as &$q)
            {
                if($q['taxonomy'] == 'product_cat')
                {
                    $q['include_children'] = false;
                }
            }
    }
    add_action('parse_tax_query', 'exclude_child_products_in_cat');
    Thread Starter Steve Weigold

    (@sweigold)

    See, the pre_get_posts is what I’m doing too. I mentioned it in my original post.

    But removing it doesn’t resolve the problem. It only makes the results different.

    Here’s my code again:

    
    function exclude_product_cat_children($wp_query) {
    	if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
    		$wp_query->set('tax_query', array(
    				array (
    						'taxonomy' => 'product_cat',
    						'field' => 'slug',
    						'terms' => $wp_query->query_vars['product_cat'],
    						'include_children' => false
    				)
    		)
    		);
    	}
    }
    add_filter('pre_get_posts', 'exclude_product_cat_children');
    
    • This reply was modified 6 years, 9 months ago by Steve Weigold.
    Thread Starter Steve Weigold

    (@sweigold)

    @mikejolley, my site is a test development site, so I wouldn’t mind granting access to someone for testing.

    I have created a fresh install also with a dowload of WP and install of WC from the add plugin menu. I have not yet been able to duplicate the problem, but I’ll keep adding things to see if I can.

    • This reply was modified 6 years, 9 months ago by Steve Weigold.
    Plugin Contributor Mike Jolley (a11n)

    (@mikejolley)

    Why mess with it? WC already allows you to show sub cats only per category. Product > categories > edit > set a display mode.

    Using tax query is likely interfering with core tax queries?

    Thread Starter Steve Weigold

    (@sweigold)

    @mikejolley, because I have cases where in some categories, I have both products AND subcategories, and I need to display both in the category page. If I select both in WC, it displays the products in the subcategories as well, which I do not want.

    Thread Starter Steve Weigold

    (@sweigold)

    Interestingly, I added my snippet in to my fresh install and in fact it broke the fresh install.

Viewing 15 replies - 1 through 15 (of 28 total)
  • The topic ‘WC 3.3.1 New issues with product category display’ is closed to new replies.