Fix: Products removed from product set when category name changed #3675
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Summary
Fixes a critical bug where products are removed from Facebook Commerce Manager product sets when a WooCommerce category name or slug is changed.
Problem
When a user edits a WooCommerce product category name:
product_typefield ❌product_type i_contains "Category Name") no longer matches the productsThis particularly affected simple products, while variable products sometimes remained due to other sync triggers.
Solution
Modified
ProductSetSync::on_create_or_update_product_wc_category_callback()to automatically resync all products in a category when the category is edited. This ensures theproduct_typefield on products gets updated with the new category name, allowing the product set filter to continue matching them correctly.Added new method
sync_products_in_category()that:product_typefieldRelated Issue
Addresses bug report where products were removed from Facebook CM product sets after category rename.
Dependencies
None - uses existing sync infrastructure.
Type of change
Checklist
Changelog entry
Fixed: Products no longer removed from Facebook Commerce Manager product sets when category name or slug is changed
Test Plan
Manual Testing Steps
Test Case 1: Category Name Change
Test Case 2: Both Name and Slug Change
Test Case 3: Variable Products
Automated Testing
Updated tests verify that
sync_products_in_category()is called when categories are created or updated.Code Review Focus Areas
includes/ProductSets/ProductSetSync.phplines 72-74: Product resync triggerincludes/ProductSets/ProductSetSync.phplines 242-286: New sync methodAdmin/Product_Categories.phplines 401-411Screenshots
Before
Issue: When category "Test Category" is renamed to "New Category":
{"and":[{"product_type":{"i_contains":"New Category"}}]}product_type: "Test Category"After
Fixed: When category is renamed:
{"and":[{"product_type":{"i_contains":"New Category"}}]}product_type: "New Category"Technical Details
Files Modified:
includes/ProductSets/ProductSetSync.phptests/Unit/ProductSets/ProductSetSyncTest.phpPattern Consistency:
This implementation follows the exact same pattern used in
Admin/Product_Categories::save_google_product_category_and_enhanced_attributes()which resyncs products when category attributes change. The approach is consistent with how variable products are handled throughout the codebase (sync variations, not parents).Performance Impact:
Minimal - product syncing is already an asynchronous operation and this occurs only during the relatively rare event of category name changes.