Inicio › Toolset Professional Support › [Resuelto] WooCommerce Views breaks custom WooCommerce template
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.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
Etiquetado: Plugin Views, Views
Este tema contiene 10 respuestas, tiene 2 mensajes.
Última actualización por Beda hace 5 años, 2 meses.
Asistido por: Beda.
I am trying to: Activate WooCommerce Views.
Link to a page where the issue can be seen: enlace oculto
Note however that we have deactivated WooCommerce Views.
I expected to see: Our page loading
Instead, I got: ERROR_CONNECTION_CLOSED
--
Please see picture attached.
WooCommerce Views is not identifying our WooCommerce template appropriately, nor does it identify the single product page template appropriately.
WooCommerce template file should be -> "/themes/nationhats/woocommerce.php"
We do not have a custom single-post.php template so I'm not sure why Toolset identify the single-glossary.php template as the correct file.
How can we select our custom woocommerce.php template file?
Thank you!
Can I see the Custom WooCommerce Product single file you use?
There are several requirements both from WooCommerce and Toolset to recognize it.
1. Does it (the custom template) work when Toolset is disabled? Does WooCommerce respect it?
2. If so, Toolset should as well, but there are minimum requirements which I can check or you can confirm personally, as I list them below, that need to be respected for the template to be recognized:
A) single-product.php require either as proper PHP code or as PHP comment:
- EITHER "the_ddlayouts"
- OR any of "have_posts", "the_post", "loop", or any string containing "loop"
- AND filesize is greater than 0 bytes (means, just put any string in the template).
==> Now the single-product.php will show up in Toolset > WCV > Settings > Product Template File
B) The archive-product.php either should have as proper PHP code or as PHP comment:
- Any string containing "loop", such as "loop", or "anyloophere" but NOT on the first file line.
- AND filesize is greater than 0 bytes (this is usually the case if any of above is true).
==> Now the archive-product.php will show up in Toolset > WCV > Settings > Product Archive Template File
If this is not true on your end, it might be there are other plugins interfering, the theme is interfering or any other thing yet unknown causes the issue.
I could in this case help by debugging it locally on a copy of your site, or if there are known steps to replicate this on a clean install, according to your instructions.
I enabled private reply sections if it becomes necessary to send copies of the site or other private data.
Also note, WooCommerce states that if your theme has a **woocommerce.php** file, you will be unable to override the **woocommerce/archive-product.php** custom template in your theme, as woocommerce.php has priority over other template files. This is intended to prevent display issues.
See https://docs.woocommerce.com/document/template-structure/
This file would not be intended for the "single" product template, which you show in the screenshot to be wrong. Maybe I misunderstand this part, please don't hesitate to correct me.
Thank you.
Hello Beda,
Thank you for the provided details.
Yes, our template works without Toolset, WooCommerce display all appropriate pages as expected.
As recommended by WooCommerce and just like you mentionned, we do not use a "single-product.php" or "archive-product.php" file since the "woocommerce.php" file override has precedence.
Please see below our custom "woocommerce.php" file:
<?php // ============================================================================= // WooCommerce page output for Nationhats. // ============================================================================= ?> <?php get_header(); // Single-Product Page if ( !is_shop() && is_singular( 'product' ) ): ?> <div class="x-main full" role="main"> <div class="x-container"> <?php while ( have_posts() ) : the_post(); wc_get_template_part( 'content', 'single-product' ); endwhile; ?> </div> </div> <?php // Category Page elseif ( !is_shop() && is_product_category() ) : ?> <?php global $wp_query; $cat = $wp_query->get_queried_object(); $thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true ); $image = wp_get_attachment_url( $thumbnail_id ); if ( $image ): ?> <div class="category-header banner"> <div class="category-banner-wrapper"> <div class="category-banner-overlay"></div> <?php echo sprintf('<div class="category-banner" style="background-image: url(\'%s\')" alt="" /></div>', $image, 1); ?> </div> <div class="category-content-wrapper"> <h1 class="category-title entry-title"><?php woocommerce_page_title(); ?></h1> <span class="category-breadcrumb" style="font-size:80%;"> <?php /*staging:19286 / live:20044 */ echo do_shortcode('[cs_gb id=20044]'); ?> <?php /*$argsd = array('delimiter' => ' / ', );?> <?php woocommerce_breadcrumb( $argsd );*/ ?> </span> <?php //do_action( 'woocommerce_archive_description' ); ?> <?php echo '<div class="term-description">' . apply_filters( 'the_content', term_description()) . '</div>';?> </div> <?php else : ?> <div class="category-header noimage"> <div class="category-content-wrapper"> <h1 class="category-title entry-title"><?php woocommerce_page_title(); ?></h1> <span class="category-breadcrumb" style="font-size:80%;"> <?php /*staging:19286 / live:20044 */ echo do_shortcode('[cs_gb id=20044]'); ?> <?php /*$argsd = array('delimiter' => ' / ', );?> <?php woocommerce_breadcrumb( $argsd );*/ ?> </span> <?php do_action( 'woocommerce_archive_description' ); ?> </div> <?php endif; ?> </div> <div class="x-main x-container product-wrap max width offset-top offset-bottom" role="main"> <?php if ( woocommerce_product_loop() ) { do_action( 'woocommerce_before_shop_loop' ); woocommerce_product_loop_start(); if ( wc_get_loop_prop( 'total' ) ) { while ( have_posts() ) { the_post(); do_action( 'woocommerce_shop_loop' ); wc_get_template_part( 'content', 'product' ); } } woocommerce_product_loop_end(); do_action( 'woocommerce_after_shop_loop' ); } else { do_action( 'woocommerce_no_products_found' ); } ?> </div> <?php // Shop Page else: ?> <?php /*$temp_query = clone $wp_query; $shoppageid = woocommerce_get_page_id('shop'); query_posts("page_id={$shoppageid}"); while ( have_posts() ) : the_post(); ?> <div class="entry-wrap"> <?php x_get_view( 'global', '_content', 'the-content' ); ?> </div> <?php endwhile; */?> <div class="category-header banner"> <div class="category-banner-wrapper"> <div class="category-banner-overlay" style="background: rgba(0,0,0,0.8);"></div> <div class="category-banner" style="background-image: url('/wp-content/uploads/2015/07/Shop-Hats-Snapback-Caps-Beanies-Headwear.jpg')" alt=""></div> </div> <div class="category-content-wrapper"> <h1 class="category-title entry-title">Store</h1> <div class="term-description"> <p>Discover all the branded hats, caps and beanies we offer</p> <p>Got an idea for your next project?<br> <a href="<em><u>enlace oculto</u></em>" class="nh-button-small">Create your own hats</a></p> </div> </div> </div> <div class="x-main full" role="main"> <div class="x-container x-container product-wrap max width offset-top offset-bottom"> <?php /*$wp_query = clone $temp_query;*/ ?> <?php if ( woocommerce_product_loop() ) { do_action( 'woocommerce_before_shop_loop' ); woocommerce_product_loop_start(); if ( wc_get_loop_prop( 'total' ) ) { while ( have_posts() ) { the_post(); do_action( 'woocommerce_shop_loop' ); wc_get_template_part( 'content', 'product' ); } } woocommerce_product_loop_end(); do_action( 'woocommerce_after_shop_loop' ); } else { do_action( 'woocommerce_no_products_found' ); } ?> </div> </div> <?php endif; ?> <?php do_action( 'woocommerce_after_main_content' ); do_action( 'woocommerce_sidebar' ); get_footer(); ?>
Waiting for your feedback!
All best,
B
WooCommerce Views adds compatibility with:
A) single-product.php require either as proper PHP code or as PHP comment:
- EITHER "the_ddlayouts"
- OR any of "have_posts", "the_post", "loop", or any string containing "loop"
- AND filesize is greater than 0 bytes (means, just put any string in the template).
==> Now the single-product.php will show up in Toolset > WCV > Settings > Product Template File
B) The archive-product.php either should have as proper PHP code or as PHP comment:
- Any string containing "loop", such as "loop", or "anyloophere" but NOT on the first file line.
- AND filesize is greater than 0 bytes (this is usually the case if any of above is true).
==> Now the archive-product.php will show up in Toolset > WCV > Settings > Product Archive Template File
I also mentioned, when you use woocommerce.php (hence neither of above-supported files) you will not be able to overwrite single or archive files. That's an intended feature/limitation made by WooCommerce itself.
WooCommerce Views can't work on that file, unfortunately.
The WooCommerce Views plugin intentionally excludes the woocommerce.php file for exactly the same reason as WooCommerce doesn't allow overwriting single or archive if using this file: you want to override WooCommerce default files in a generic way in PHP, hence there is no need for WooCommerce Views to load that template, which is not ready for single finetuned styling using WooCommerce Views.
You should either use WooCommerce Views plugin default templates and style them, with the Plugin instead of PHP or override your theme's product and archive files for it.
You can also read more information here in an older thread:
https://toolset.com/forums/topic/woocommerce-php-being-ignored-in-single-product-page/#post-402628
I understand we'll have to change our approach to customizing WooCommerce pages if we want to enable WooCommerce Views.
I'd like maybe to share some feedback that it would be great to have a better error handling for custom installs already using woocommerce.php in their child-theme. An Error 500 isn't very nice. Enabling the plugin should not break anything if WooCommerce views isn't able to properly lock into the right template files.
We'll have to split our code to match the single-product.php/archive-product.php workflow.
My issue is *partially* resolved. Thank you!
In the current new WooCommerce Views release there have been changes, related to the mechanism of recognizing the templates.
We make sure to recognize any single or archive /shop, it's up to the developer, if creating custom archives, to provide the proper content in them.
I also asked to add woocommerce.php but the nature of that file is different, and requires careful tests - we may however add it in future, the Developers where not against including it, it just requires more time and checks to implement this.
It's by default not yet supported, only custom single or archive would be. There was little need for this, until now I saw no other users attempting to style custom woocommerce.php templates with WooCommerce Views, however we consider every case and suggestion.
I think the best here would be to request this as a feature, so the Product Management can eventually consider this in a development cycle, considering eventual other voices requesting this.
You can request this here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Now, an error 500 or any kind of PHP error should not happen, that is correct.
I am reopening the ticket to check upon that, and will feedback asap.
In a local install with all required plugins, the template you provide here simply will not be recognized and not offered in the Woocommerce Views settings - also there will not be offered another, maybe wrong path.
Simply only the supported files of a theme and WooCommerce Views Plugin are offered, I attached a screenshot after applying the template you use in a theme's woocommerce.php (which applies to the front end just fine, as long I do not alter the settings in Woocommerce Views or save them, logically, as then the setting will kick in that is provided there).
I can always choose WooCommerce Plugin Default Templates, and that will preserve the exact woocommerce.php template but of course not allow me to design it with Content Templates.
For that I need to either activate WooCommerce Views templates or create some supported templates.
As soon I choose WooCommerce Views templates I also see them on the front end, despite a woocommerce.php being in the theme.
I saw no issues so far, this may be due to the updates.
Can you still replicate this issue?
Hello Beda,
Activating Toolset Views, I have no more Error 500. The shop page is also reachable.
Single products however return an Error 502.
It still tries to use the following file for the product template: wp-content/themes/nationhats/search-pages.php (identified as the Custom Page Template).
The second choice is: wp-content/themes/nationhats/single-glossary.php (identified as the Custom Post Template).
These may not be selected by default in a vanilla install as these files wouldn't be present of course.
Selecting the default WooCommerce template for the product template the Error 502 on single product pages goes away, but then we can't really customize anything as you mentionned.
My suggestion: Detect if there is a woocommerce.php file in the current active theme/child-theme and disable all WooCommerce Views feature. This will prevent single product pages from breaking on plugin activation.
I went ahead and submitted a feature suggestion.
Thanks again!
All best,
B
OK, I can definitely not replicate this problem on any Install I own.
The code simply does not allow to catch any file but the expected ones for single and archive (shop).
That's visible in the code, so unless those files you receive there have a wrong template name, it cannot show them as valid files: they are not listed as valid by the code, since only 2 are allow to be (single produce and archive/shop)
When you select the Woocommerce Views templates, then you can (that is the entire purpose of) edit those single and shop templates in Toolset > Content Templates (or layouts, if you use layouts), by creating a new Content Template for the single product, and in Toolset > WordPress Archives you will be able to style shop and term archives.
That works flawlessly as long you selected the Toolset Templates, or your templates offer the right code for those to work.
Disabling all Woocommerce Views features if XY is true is not solving or helping here.
You could simply disable the plugin, if you want all features disabled when a certain template is present.
That is what we usually recommend when you do not want to style those with the Toolset.
However many users want to use Woocommerce Views not for styling but calculation and search.
So in those cases, they will use custom templates (and mark it so on the Woocommerce Views settings) and not use designable templates, but just the under-the-hood features of Toolset Woocommerce Views.
Now, at this point I think I need to look at your install locally.
The issues you describe are not expected, and stop you from working, so we need to solve them.
Can you add a complete copy of the site with the issue, describe where and how I will see the issue if anything particular?
You can see here how to create a copy that can be used for this:
https://toolset.com/faq/provide-supporters-copy-site/
I will then have a look and update you on possible resolutions.
Thanks!
Hey Beda,
Tested a few things on a vanilla install...
w/ 2019 Theme
Product Template File – Page template suggested -> /wp-content/themes/twentynineteen/page.php
Product Template File – Posts template suggested ->/wp-content/themes/twentynineteen/single.php
Product Template File – WooCommerce template suggested ->/wp-content/plugins/woocommerce/templates/single-product.php
Product Template File – WooCommerce Views template suggested* -> /wp-content/plugins/woocommerce-views/templates/single-product.php
*Selected by default
Product Archive Template File – WooCommerce Plugin Default* – /wp-content/plugins/woocommerce/templates/archive-product.php
Product Archive Template File – WooCommerce Views – /wp-content/plugins/woocommerce-views/templates/archive-product.php
*Selected by default
**Accessing both the shop and single product page works**
___
w/ Pro-Child Theme
Product Template File – Page template suggested -> /wp-content/themes/pro-child/search-pages.php
Product Template File – Posts template suggested -> **N/A** _This is new, it used to pick archive-glossary.php_
Product Template File – WooCommerce template suggested* -> /wp-content/plugins/woocommerce/templates/single-product.php
Product Template File – WooCommerce Views template suggested -> /wp-content/plugins/woocommerce-views/templates/single-product.php
*Selected by default
Product Archive Template File – WooCommerce Plugin Default* – /wp-content/plugins/woocommerce/templates/archive-product.php
Product Archive Template File – WooCommerce Views – /wp-content/plugins/woocommerce-views/templates/archive-product.php
*Selected by default
**Accessing both the shop and single product page works**
---
At this point I thing the problem comes from our particular environment on our live site.
My suggestion to disable things if XY is true wouldn't necessarily fix anything, just prevent some display issues. I'm not sure why Toolset WooCommerce Views had the wrong template enabled by default, this doesn't seem to happen on a vanilla install though.
Anyway, Juan sent me a message saying next update should include better support for woocommerce.php so this will probably be fixed soon.
Thanks for your help as always Beda!
Yes, but Woocommerce.php support will not resolve the problem I see there, which seems to be, the template offered is simply a wrong one (if I understand search-pages correctly, it0's not a single WooCommerce template).
Is this correct?
In this case it does not really matter if we add a WooCommerce.php support but we would need to check why there is a wrong template detected.
By Default Toolset should select "WooCommerce Plugin Default Templates" if enabled the first time, and it should not offer templates not named properly, which this one does not seem to be.
Can I have a copy of that theme? It seems to me there is some incompatibility with Toolset, or maybe just WooCommerce, I can help find out and eventually even fix.
I have enabled the private reply for you to provide a copy if possible.