Skip to content

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

Merged
merged 2 commits into from
Jun 29, 2021

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Jun 21, 2021

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:

  • WP 5.8 or Gutenberg plugin enabled.
  • A classic theme.

Steps:

  1. Go to create a new page, in the sidebar, create a new template:

  2. Make some edits and click on Publish. Make sure the template you created is marked for publishing:

  3. Now, go to edit a product.
  4. Verify there is no metabox in the sidebar that lets you change the template.



    (this is what you shouldn't see) 👆

Changelog entry

Exclude block templates from showing up in product edit page

@Aljullu Aljullu added Enhancement The issue is a request for an enhancement. category: templating labels Jun 21, 2021
@Aljullu Aljullu added this to the 5.5.0 milestone Jun 21, 2021
@Aljullu Aljullu requested review from nerrad and vedanshujain June 21, 2021 18:42
@Aljullu Aljullu self-assigned this Jun 21, 2021
vedanshujain
vedanshujain previously approved these changes Jun 25, 2021
Copy link
Contributor

@vedanshujain vedanshujain left a 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.

Copy link
Contributor

@nerrad nerrad left a 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 );
Copy link
Contributor

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)?

@frontdevde
Copy link
Contributor

Tested as per testing instructions and it worked as expected for me.

before after
Screenshot 2021-06-29 at 12 36 06 Screenshot 2021-06-29 at 12 36 41

there should probably be a function_exists check before calling it (maybe in the initial check at the beginning of the function logic)

As Albert is AFK at the moment, I added a small commit that hopefully addresses Darren's comment (who is AFK as well). As suggested, I added a check to test if the gutenberg_get_block_template function exists at the beginning of the function logic.

Also, I didn't verify, but I'm assuming this filter is only executed on WC Admin product editor routes?

During my testing, that appeared to be the case, yes.

@frontdevde frontdevde requested a review from nerrad June 29, 2021 11:26
Copy link
Contributor

@nerrad nerrad left a 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 👍🏻

@vedanshujain vedanshujain merged commit 89aac04 into trunk Jun 29, 2021
@vedanshujain vedanshujain deleted the fix/30136-no-block-templates-for-products branch June 29, 2021 11:42
@woocommercebot woocommercebot added release: add changelog Mark all PRs that have not had their changelog entries added. [auto] release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto] labels Jun 29, 2021
@vedanshujain vedanshujain added release: cherry-pick Commits from this PR also needs to be added to current release branch. and removed release: cherry-pick Commits from this PR also needs to be added to current release branch. release: add changelog Mark all PRs that have not had their changelog entries added. [auto] labels Jun 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement The issue is a request for an enhancement. release: add testing instructions PRs that have not had testing instructions added to the wiki. [auto]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hide template selector from Edit product pages in WP 5.8
5 participants