Only sync selected categories as product type #2233
Merged
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.
Changes proposed in this Pull Request:
This PR changes the behaviour to only sync the selected categories as product type. Previously it would sync parent categories, both included as the parent of a child category as well as the parent individually even if the parent wasn't selected directly.
This change switches from using
wc_get_product_cat_ids
to usingwc_get_product_term_ids
as the first function will include a list of ancestors (regardless of whether they are selected or not). The latter function will return a list of all the selected categories. Which means we can influence which parent categories get synced individually by selecting them or not.I altered the unit test to match the expected behaviour as well as testing some more edge cases to ensure they are synced correctly:
Closes #2230
Detailed test instructions:
Changelog entry