Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Research how extensions extend archive templates #8064

Closed
Tracked by #8059
dinhtungdu opened this issue Jan 2, 2023 · 4 comments
Closed
Tracked by #8059

Research how extensions extend archive templates #8064

dinhtungdu opened this issue Jan 2, 2023 · 4 comments
Assignees
Labels
focus: FSE Work related to prepare WooCommerce for FSE. focus: template Related to API powering block template functionality in the Site Editor

Comments

@dinhtungdu
Copy link
Member

dinhtungdu commented Jan 2, 2023

We need to research how extensions are extending archive templates. We aim for some metrics:

  • What are the most frequently used actions?
  • What are the most frequently used filters?

To limit the scope of the research and ensure that we can get some outcome, we will examine extensions and themes on WooCommerce.com only.

@dinhtungdu dinhtungdu added focus: template Related to API powering block template functionality in the Site Editor focus: FSE Work related to prepare WooCommerce for FSE. labels Jan 2, 2023
@dinhtungdu dinhtungdu self-assigned this Jan 6, 2023
@dinhtungdu dinhtungdu changed the title Research how themes and extensions extend archive templates Research how extensions extend archive templates Jan 6, 2023
@dinhtungdu
Copy link
Member Author

dinhtungdu commented Jan 6, 2023

Hooks usage in WooCommerce.com extensions

The table shows that the loop and loop item hooks are extended most, which gives us a narrower focus on implementing the compatibility layer.

Hook Count
woocommerce_after_shop_loop_item 85
woocommerce_after_shop_loop_item_title 44
woocommerce_before_shop_loop 21
woocommerce_shop_loop_item_title 21
woocommerce_before_shop_loop_item_title 19
woocommerce_after_shop_loop 17
woocommerce_before_shop_loop_item 13
woocommerce_no_products_found 13
woocommerce_after_main_content 10
woocommerce_archive_description 9
woocommerce_before_main_content 8
woocommerce_show_page_title 1
woocommerce_shop_loop 0
woocommerce_sidebar 0

@dinhtungdu
Copy link
Member Author

With Blocks Editor, we can skip these hooks:

  • woocommerce_show_page_title
  • woocommerce_archive_description
  • woocommerce_sidebar

woocommerce_before_main_content and woocommerce_after_main_content is tricky to implement the exact behavior, but I think wrapping them around the Products block should be sufficient enough.

Other hooks can be prepended/appended to the render function of the corresponding block through the render_block filter. It's possible to process only blocks belonging to the Products block that inherit query from the templates by modifying the block data using the render_block_data filter.

What do you think @nerrad @Aljullu?

@nerrad
Copy link
Contributor

nerrad commented Jan 9, 2023

We'll also want to make sure we remove_action/filter for callbacks that add content non-relevant to the context right (for instance on woocommerce_before_main_content:

The same will need to be evaluated for any other hooks.

@dinhtungdu
Copy link
Member Author

The archive templates only work with block themes, so we won't need to care about theme compatibility here (which is for classic themes). We will remove the default output wrapper as we don't need it for archive templates.

We will also remove actions that are replaced by our blocks, such as notices, catalog orders, or results count. WooCommerce template system needs those hooks but our archive templates don't, so we will remove most of the default actions added by Woo. The actions will be mainly for extensions to continue working with our blockified templates.

Definitely.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: FSE Work related to prepare WooCommerce for FSE. focus: template Related to API powering block template functionality in the Site Editor
Projects
None yet
Development

No branches or pull requests

2 participants