Fix: Add validation guard for product object in admin settings tab #3684
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.
Summary
Fixes #2894
Prevents fatal TypeError when
wc_get_product()returns false by adding defensive type checking before rendering product fields in the admin.Problem
The
add_product_settings_tab_content()function callswc_get_product($post)which can returnfalsein certain scenarios:This
falsevalue is then passed torender_google_product_category_fields_and_enhanced_attributes()which expects aWC_Producttype, causing a fatal TypeError that completely blocks product editing.Error:
Solution
Added defensive validation in
includes/Admin.phpbefore calling the render function:$productis false/null, attempts to retrieve it usingwc_get_product($post->ID)$product instanceof \WC_ProductChanges
File:
includes/Admin.php(lines 1318-1332)Testing
Test Plan
Risk Assessment
Risk Level: Very Low
Closes #2894