-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Exclude block templates from showing up in product edit page #30138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude block templates from showing up in product edit page #30138
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and working as expected. I will leave it for @nerrad to do a final review before merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment that should probably be addressed before merging (assuming the gutenberg_get_block_template
function only appears in WP 5.8+).
Also, I didn't verify, but I'm assuming this filter is only executed on WC Admin product editor routes?
Other than the above, this looks great!
$filtered_templates = array(); | ||
|
||
foreach ( $templates as $template_key => $template_name ) { | ||
$gutenberg_template = gutenberg_get_block_template( $theme . '//' . $template_key ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function WP version specific? If so, there should probably be a function_exists
check before calling it (maybe in the initial check at the beginning of the function logic)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @frontdevde - looks good to me 👍🏻
This PR hooks into the
theme_product_templates
filter in order to filter out block-based templates from appearing as template options in the product edit page. This way, templates created with the template editor included in WP 5.8 do not appear in the product edit page.The rationale is that currently WooCommerce relies on PHP templating to format the product page so templates chosen from that selector have no effect in the frontend of classic themes.
In the future, we might enable the selector again for block-based themes. But that would require some investigation on how we can ensure only templates relevant to products show up in the selector (related issue in Gutenberg: WordPress/gutenberg#31704).
Closes #30136.
How to test the changes in this Pull Request:
Requisites:
Steps:
(this is what you shouldn't see) 👆
Changelog entry