Skip Navigation

[Resuelto] WooCommerce category archive doesn't work with both products and sub-categories

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
Categories where there are both products as well as further sub-categories, Views styling does not affect the sub categories.

Solution:
1. Ensure product categories are set to display as products
2. Create a new View that will solely display the product subcategory on a product category page.
3. Use the WooCommerce Views new conditional built-in function (new in version 2.5.3)

woo_has_product_subcategory()

to check if the loaded product category page has a subcategory.
4. Implement this with wpv-if on 'Products, Product Categories' WordPress archive View

When a product category with subcategory is loaded

woo_has_product_subcategory()

returns 1 and executes the 'Customize Product SubCategory' View. This View is responsible for displaying the product subcategories and this is where we can add styling, etc for subcategories.

But when the product categories don't have subcategories on it but only display products

woo_has_product_subcategory()

returns 0 and therefore execute the normal archive code just like it was before.

This support ticket is created hace 6 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Etiquetado: 

This topic contains 8 respuestas, has 2 mensajes.

Last updated by Beda hace 6 años, 10 meses.

Assigned support staff: Beda.

Autor
Mensajes
#312774

I am trying to edit the WordPress Archive View for WooCommerce Product Categories. Editing the view allowed me to customise the list of products within the product category successfully however in categories where there are both products as well as further sub-categories the view is messed up as my styling in the view does not affect the sub categories.

How can I resolve this?

To see this in action:

Page with just products working fine:
hidden link

Page with products and sub-categories:
hidden link

Please note this site is an adult store and as such contains some product images with nudity. The two links I've provided though do not.

Password to access the site is bdsmshop:Development!

Current Views Code:

<div class="breadcrumbs">[yoast-breadcrumbs]</div>
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->		
[wpv-add-to-cart-message]
<ul class="products">
	<wpv-loop>
		<li class="item">
			<a href="[wpv-post-url]" class="product-link">
				<div class="bg product-title">[wpv-post-title output="sanitize"]</div>
				<img height="200" class="attachment-shop_catalog wp-post-image" src="[wpv-woo-product-image size="shop_catalog" output="raw" gallery_on_listings="no"]">
			</a>
			[wpv-woo-product-price]
			<div class="add_to_cart">
				[wpv-woo-buy-or-select add_to_cart_text="Buy Now" link_to_product_text="More Info" show_quantity_in_button="yes" show_variation_options="no"]
			</div>
		</li>
	</wpv-loop>
</ul>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No posts found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
#312976

Thank you for contacting us here in the Support Forum

To help you better and see the Views and Settings closer, I would like request temporary access (WP-Admin and FTP) to your site
- preferably to a test site where the problem has been replicated if possible -
in order to be of better help and check if some configurations might need to be changed

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

Meanwhile, can you confirm to have consulted this DOC's:
https://toolset.com/documentation/user-guides/normal-vs-archive-views/
https://toolset.com/learn/create-an-ecommerce-wordpress-site/

Please also see this Thread, it seems to explain how to solve the issue you mention.
https://toolset.com/forums/topic/design-woocommerce-product-categroy-and-sub-cateogry-page/#post-286792

Please could you provide me the access in case it doesn't help so I can see the install closer?

Please don't hesitate to inform me in case the issue persists

Thank you

#313703

Thanks for the Details and please apologize the late reply.

I have accessed both links this morning and the content seems different.

Also navigating the sub-categories, it seems to me the Archives all are styled the same and use the same Mockup?

Please don't hesitate to correct me in case the situation changed and I can find the problematic View in another location.

It would also be good if you could update the WooCommerce Views and Types Plugins.

Please don't hesitate to inform me in case the issue persists

Thank you

#313778

Sorry about the confusion, some changes have been made since my original post and those links are no longer a good reflection of the problem please see the following two links:

hidden link

hidden link

The first link is the problem, I can't seem to work out how to control the subcategories appearance with views. It should ideally display almost the same as the second link just without the pricing/buy now links as they are categories and not individual products.

I've also run WordPress updates on Types and WooCommerce Views.

#314025

Thanks for the Details

I am seeking advice from the second Tier Support, as what I tried did not work on your site.

Actually, the main problem is that your Archive View does not apply at all on the Category Archive Page as long that page is ONLY listing Categories and no products.

This is so far expected for the single "elements" on that page, as you include only styling for products in the archive page view's loop, but I am missing to apply your breadcrumbs as well on parent category pages, as long no products are listed.

Also, our own BreadCrumb ShortCode can't be used here as it is intended for usage on Single Product Pages.

I must inform you that I have created a new Archive View, just for categories (product categories) and if possible, I would need to kindly ask you to leave it for now as it is,
also the two pages you linked to above, could you, if possible, no perform any changes to them so 2nd Tier can see the same issue as I (and you) do?

I will update you here as soon I have more advice from the 2nd Tier.

Thank you for your patience

Please expect my informations here in the forum.

Thank you

#314449

Any word back from 2nd tier support yet?

With regards to breadcrumbs that's not a problem, I'm using the Breadcrumbs from the Yoast SEO plugin instead of the WP-Types breadcrumbs so no issue there.

#315138

I apologize the delay here

The 2nd Tier fixed the main issue on your site.
To summarize:

WooCommerce Views depends on our Views plugin for display content. But the WooCommerce core plugin has three modes of display for product categories:

a.) Display product categories by products
b.) Display product categories by subcategories
c.) Display both.

You can see this setting in the WordPress backend through Products -> Categories and click "For her" as an example to edit.
(I missed that too 🙂 )

You should see the 'Display Type' field. There is where you can configure how the product categories are to be displayed.

The current limitation is that Views plugin only displays 'by products' when we are assigning a WordPress archive to a Product category.
As a result, when a product category has a subcategory, WooCommerce overrides it and and Views can no longer control this.

Therefore the solution of this problem are as follows:

1.) Ensure product categories are set to display as products
[...]edit-tags.php?action=edit&taxonomy=product_cat&tag_ID=185&post_type=product

So its consistent with Views.

2.) Create a new View that will solely display the product subcategory on a product category page.

The 2nd Tier created this on the site here:
[...]admin.php?page=views-editor&view_id=13825

This is the View that we where looking into to customize the styling on product subcategory pages so it would be consistent with the other product category archive looks.

3.) Use the WooCommerce Views new conditional built-in function (new in version 2.5.3) woo_has_product_subcategory() to check if the loaded product category page has a subcategory.

Implement this with wpv-if on 'Products, Product Categories' WordPress archive View:
[...]/admin.php?page=views-editor&view_id=13825

This is the revised markup on the loop output:

<div class="breadcrumbs">[yoast-breadcrumbs]</div>
[wpv-layout-start]
[wpv-if evaluate="woo_has_product_subcategory() = 0"]
    [wpv-items-found]

    <!-- wpv-loop-start -->        
        [wpv-add-to-cart-message]
 <ul class="products">    
        <wpv-loop>
         <li class="item"><a href="[wpv-post-url]" class="product-link">
            <div class="bg product-title">[wpv-post-title output="sanitize"]</div>
            <img height="200" class="attachment-shop_catalog wp-post-image" src="[wpv-woo-product-image size="shop_catalog" output="raw" gallery_on_listings="no"]">
            </a>
            [wpv-woo-product-price]            
            <div class="add_to_cart">
              [wpv-woo-buy-or-select add_to_cart_text="Buy Now" link_to_product_text="More Info" show_quantity_in_button="yes" show_variation_options="no"]
            </div>
          </li>
        </wpv-loop>
</ul>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
        <strong>[wpml-string context="wpv-views"]No posts found[/wpml-string]</strong>
    [/wpv-no-items-found]
[/wpv-if]
[wpv-if evaluate="woo_has_product_subcategory() = 1"]
[wpv-view name="Customize Product SubCategory"]
[/wpv-if]
[wpv-layout-end]

How it works:

When a product category with subcategory is loaded, e.g. here:
[...]product-category/for-her/

woo_has_product_subcategory() returns 1 and executes the 'Customize Product SubCategory' View. This View is responsible for displaying the product subcategories and this is where we can add styling ,etc for subcategories.

But when the product categories don't have subcategories on it but only display products 'woo_has_product_subcategory()' returns 0 and therefore execute the normal archive code just like it was before.

Does this help to solve the main issue of this thread?

Please don't hesitate to inform me in case you have further questions

Thank you for your patience.

#315183

That's awesome, that appears to resolve that issue completely!

All I need to do is assign all the categories to that Products display type so that Views can intercept everything?

Not crucial but a quick question, If I had a category that had both products & subcategories could I display both using the same or similar markup? My thoughts would be to start with subcategories:

[wpv-if evaluate="woo_has_product_subcategory() = 1"]
[wpv-view name="Customize Product SubCategory"]
[/wpv-if]

Then just remove this if statement? (Assuming the [wpv-items-found] would take care of if it if there are products or not?)

[wpv-if evaluate="woo_has_product_subcategory() = 0"]
#315222

Well, you would need to make sure the sub-category displays as Product.

woo_has_product_subcategory()

checks whether it has or not a subcategory. On "1", it returns the new View, on "0" it returns the Loop mentioned above.
As long as the loaded category has a subcategory, it will return 1, otherwise its 0.

Therefore, if you have both on one Page (Category with Subcategory and Products), it should return already both Views.

Perhaps I misunderstand the query.
If any issues with this (new) function arise, we should handle it in a new Thread.

Please acknowledge that this is a new feature, not yet released officially :). Though, it should work as expected above.

Please do not hesitate to open a new thread if other issues or problems arise

Thank you