Skip to content

Fix: Implement woocommerce_merged_packages filter #58975

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

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

doubleedesign
Copy link

@doubleedesign doubleedesign commented Jun 19, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

The comment above the definition of $merged_packages in the Packages class says "the packages included in this array can be deactivated via the 'woocommerce_merged_packages' filter", but that filter has not actually been implemented. This PR adds it to the get_enabled_packages method, enabling plugin authors to selectively disable packages such as Brands like so:

function disable_woocommerce_brands($packages) {
  unset($packages['woocommerce-brands']);
  
  return $packages;
};
add_filter('woocommerce_merged_packages', 'disable_woocommerce_brands');

This change does not delete any data from the database, so re-enabling the feature restores any previous data throughout the admin and front-end automatically. All that is required is re-saving permalinks so that any relevant URLs are restored (e.g., brand archives if disabling/re-enabling Brands).

How to test the changes in this Pull Request:

  1. Create a minimal plugin containing the filter usage example above.
  2. Activate WooCommerce. Observe that Brands is enabled by default.
  3. Add a brand and assign it to a product. Observe that it is listed on the front-end if using default templates.
  4. Activate your minimal test plugin. Go to Settings -> Permalinks and click "save" to refresh permalinks.
  5. Observe that Brands is now disabled in the admin, e.g.:
    • Brands menu item is not present in the Products submenu
    • Brands filter is not present in the product list
    • Brands column is not visible in the admin product list
    • Brands metabox is not present when editing a single product
  6. Observe that Brands are no longer shown on the front-end, e.g.:
    • Single product page no longer shows the brand alongside the category
    • URL for a single brand e.g. /brand/test-brand/ returns a 404.
  7. Disable your minimal test plugin and refresh permalinks again.
  8. Observe that the Brands functionality has returned to both the admin and the front-end. Data for previously saved brands has remained intact.

Testing that has already taken place:

  • Implementation in a clean install with the default theme, WooCommerce, and a minimal custom plugin only (no other plugins). Confirmed that Brands is removed from the admin and front-end as per the above, including when some brands have been created and assigned to products.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

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

Add ability for developers to disable packages that are developed outside of core (but are enabled in core via the Packages class) by using the woocommerce_merged_packages filter to unset unwanted packages.

Enables ability to disable packages such as Brands from a plugin or theme using a filter.
Copy link
Contributor

coderabbitai bot commented Jun 19, 2025

Walkthrough

A new WordPress filter hook, woocommerce_merged_packages, has been added to the WooCommerce Packages class. This allows developers to modify the list of enabled merged packages before they are finalized, providing a way to customize or disable specific externally developed packages in the WooCommerce core.

Changes

File(s) Change Summary
plugins/woocommerce/src/Packages.php Added woocommerce_merged_packages filter to allow modification of enabled merged packages.
plugins/woocommerce/changelog/58975-fix-implement-merged-packages-filter Documented the new filter hook and its purpose.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant WooCommerce Core
    participant Packages Class

    WooCommerce Core->>Packages Class: get_enabled_packages()
    Packages Class->>Packages Class: Collect enabled merged packages
    Packages Class->>Developer: Apply 'woocommerce_merged_packages' filter
    Developer-->>Packages Class: (Optionally) modify packages array
    Packages Class->>WooCommerce Core: Return final packages array
Loading

Poem

In WooCommerce's garden, new hooks now bloom,
A filter for packages, dispelling the gloom.
Developers cheer, with options anew—
To prune or to merge, the choice is with you!
🎩🐇✨


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2410c59 and 02f17c8.

📒 Files selected for processing (2)
  • plugins/woocommerce/changelog/58975-fix-implement-merged-packages-filter (1 hunks)
  • plugins/woocommerce/src/Packages.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: label_project
🔇 Additional comments (2)
plugins/woocommerce/src/Packages.php (1)

155-156: LGTM! Perfect implementation of the documented filter.

The filter implementation correctly aligns with the existing class documentation at line 58, which already stated that merged packages "can be deactivated via the 'woocommerce_merged_packages' filter." The placement after feature flag evaluation but before merging with base packages is ideal, allowing developers to override the computed enabled packages list while preserving core functionality.

plugins/woocommerce/changelog/58975-fix-implement-merged-packages-filter (1)

1-4: LGTM! Changelog entry accurately documents the new feature.

The entry correctly categorizes this as a minor addition and clearly explains the new developer capability. The description provides sufficient detail about the filter's purpose and usage.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added type: community contribution plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Jun 19, 2025
@doubleedesign doubleedesign changed the title Fix(Packages): Implement woocommerce_merged_packages filter Fix: Implement woocommerce_merged_packages filter Jun 19, 2025
@doubleedesign doubleedesign marked this pull request as ready for review June 19, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant