Skip to content
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

Tweak useProductTemplate's logic and add new filter to allow changing the product template #47559

Closed
wants to merge 11 commits into from

Conversation

nathanss
Copy link
Contributor

@nathanss nathanss commented May 16, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Tweak useProductTemplate's logic and add a new filter to allow changing the product template.

This demand came while migrating an extension where I needed to control the product template loaded depending on the parent's data to ensure backward compatibility with products created in the legacy editor (since new ones have the product template ID persisted to them).

I've also added a variable product template, which doesn't show in the list. I found that it simplifies the logic and makes it more robust since the special handling starts to get tough when adding new templates supporting variable products.
Please let me know if any issues with this idea.

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Install and activate the following plugin:
    test-change-template.zip
  2. Enable the new product editor at /wp-admin/admin.php?page=wc-settings&tab=advanced&section=features
  3. Go to Products > Add (alternatively, open an already created variable product and skip to step 6)
  4. Go to the Variations tab
  5. Add variation options
  6. Click 'Edit' on a Variation
  7. Check the console, the extension installed should log the filter's parameters and change the variation's product template to 'grouped-product-template' (you should see 'This is a grouped product.' in the General tab).
  8. There will be some blocks with errors since some blocks don't play well with variations, but it's OK, since the extension is just to prove the concept (please disable it after testing).
  9. Disable the plugin and smoke test creating a simple product, a variable product, and a grouped product.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@github-actions github-actions bot added package: @woocommerce/data issues related to @woocommerce/data plugin: woocommerce Issues related to the WooCommerce Core plugin. labels May 16, 2024
@@ -63,29 +63,25 @@ protected function is_product_supported( $product_id ): bool {
return false;
}

$digital_product = $product->is_downloadable() || $product->is_virtual();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this since it was unused

Copy link
Contributor

github-actions bot commented May 16, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@nathanss nathanss closed this May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: @woocommerce/data issues related to @woocommerce/data plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant