woocommerce / woocommerce-blocks

(Deprecated) This plugin has been merged into woocommerce/woocommerce
https://wordpress.org/plugins/woo-gutenberg-products-block/
GNU General Public License v3.0
404 stars 218 forks source link

Consider removing the code that excludes block templates from showing up in product edit page #5029

Closed Aljullu closed 2 years ago

Aljullu commented 2 years ago

In preparation for WP 5.8, we disabled the option to change the block template of each individual product (see https://github.com/woocommerce/woocommerce/pull/30138).

That decision was based on a couple of reasons:

  1. There was a bug in Gutenberg that made all templates to appear, even if they were not related to that post type. This has been fixed: https://github.com/WordPress/gutenberg/issues/31704.
  2. We didn't have WC blocks to render the single product template. This is being tackled by the Store Editing Templates project.

Given that the first issue has been solved and the second issue will be solved, we should evaluate whether we can revert that change.

To reproduce

  1. Install a block theme and add a single-product.html template in /my-theme/block-templates/single-product.html:
    <!-- wp:template-part {"slug":"header","tagName":"header","className":"site-header","layout":{"inherit":true} /-->
    <!-- wp:woocommerce/legacy-template { "template": "single-product" } /-->
    <!-- wp:template-part {"slug":"footer","tagName":"footer","className":"site-footer","layout":{"inherit":true} /-->
  2. Add this to theme.json:
    "customTemplates": [
    {
        "name": "single-product",
        "title": "Product page",
        "postTypes": [
            "product"
        ]
    }
    ]
  3. Go to wp-admin > Products and edit a product.
  4. Notice there is no option to change the template there.
  5. If the changes in https://github.com/woocommerce/woocommerce/pull/30138 were reverted, it would be possible to change the template: imatge
dinhtungdu commented 2 years ago

After testing removing the filter added in woocommerce/woocommerce#30138 against the latest trunk of woocommerce-gutenberg-products-block, I found:

So for now, IMO, what we can do is replace the filter added in woocommerce/woocommerce#30138 with another filter that removes only the single-product template.

The one that's holding me from removing the filter is the custom templates created in the Template Editor. Users should have the ability to limit the template to post types or specific pages. Currently, all custom templates are available for all post types that support page templates.

dinhtungdu commented 2 years ago

After discussing this issue on Slack, we agree to address this issue in Store Editing Templates project v2.

Some notes from the discussion:

Related to display conditions:

Albert Juhé Lluveras: we might want to check with Gutenberg developers to know what they think about this. I found some discussion on this here, but I'm not sure to understand the resolution.

Tung Du: From another perspective, all custom templates created in the Template Editors are user-created content, so it should be users’ responsibility to “not surprised” if there are some un-related templates in the dropdown. But it’s a bad UX IMO, users should be able to choose the display condition at least, then it’s up to them to do that or not. Extending the above point, I even think that custom templates created in the Template Editor must have display conditions to be included in the dropdown. It means that we can filter out all templates that aren't assigned to the current post type. But it also means that we will remove all user-created templates.

Related to default template:

Albert Juhé Lluveras: Just a note on that, which is something we need to keep in mind for the testing phase. The same rules from PHP templating from WP apply to block templates. That means that it's possible to have a single-product-hoodie template that would be applied to the Hoodie product. I'm not sure if that actually works right now, but wanted to bring it here because in some cases, "Default template" and single-product might be different. So in those cases we might want to display both in the selector.

Tung Du: We can extend the template registration in theme.json to support category/tag, etc. Then we can share the same display conditions logic between Template Editor and theme.json.

github-actions[bot] commented 2 years ago

This issue has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface issues for review. If you are the author of the issue there's no need to comment as it will be looked at.

Internal: After 10 days with no activity this issue will be automatically be closed.
github-actions[bot] commented 2 years ago

This issue has been marked as stale because it has not seen any activity within the past 60 days. Our team uses this tool to help surface issues for review. If you are the author of the issue there's no need to comment as it will be looked at.

Internal: After 10 days with no activity this issue will be automatically be closed.