fix(woocommerce): persist custom meta on new product first save#4715
Open
dkoo wants to merge 2 commits into
Open
fix(woocommerce): persist custom meta on new product first save#4715dkoo wants to merge 2 commits into
dkoo wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
🎉 This PR is included in version 6.39.4-hotfix-nppd-1485-group-subscription-meta-unsaved-product.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes WooCommerce admin “first save” behavior where Newspack custom product options could be dropped when creating a new product and changing its type via the product-type dropdown (due to hook ordering causing $product->get_type() to still read as simple during woocommerce_process_product_meta).
Changes:
- Derive the effective product type from
$_POST['product-type'](sanitized) duringsave_custom_product_options, with fallback to$product->get_type(). - Use the derived
$product_typeforproduct_typesfiltering when persisting custom option meta.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
All Submissions:
Changes proposed in this Pull Request:
Fixes a bug where Newspack's custom product options (e.g., Group subscription enabled flag and member limit) were silently dropped on the first save of a brand-new product whose type was being changed via the product-type dropdown (e.g., new product → "Simple subscription"). Subsequent edits to existing products were unaffected.
Root cause: Both
WooCommerce_Products::save_custom_product_optionsand WC core'sWC_Meta_Box_Product_Data::saveare hooked onwoocommerce_process_product_metaat priority 10, so the order depends on registration timing. Newspack registers first, which means at the moment our handler runs,$product->get_type()still returns the auto-draft default (simple) — WC hasn't yet updated the product-type term. Our type-filter atclass-woocommerce-products.php:289then skips options whoseproduct_typeslist doesn't includesimple(Group subscription requiressubscriptionorsubscription_variation).Fix: Read the product type from
$_POST['product-type']as the source of truth, falling back to$product->get_type()when not present (REST, programmatic saves). Mirrors WC core's own pattern inWC_Meta_Box_Product_Data::save().Closes NPPD-1485.
How to test the changes in this Pull Request:
define( 'NEWSPACK_CONTENT_GATES', true );inwp-config.phpso the Group subscription option is registered.5.POST /wp-json/wc/v3/products) and the new WC product block editor bypasswoocommerce_process_product_metaentirely and are not covered by this PR. To be tracked in a follow-up.Other information:
WC_Productmock attests/mocks/wc-mocks.php(noupdate_meta_data/save/get_status/get_date_*) is out of scope for this hotfix. Verified empirically against a live env. Follow-up ticket recommended.n test-php: 924 tests, 2859 assertions, all passing.