Skip to content
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

Try: Add product editor hooks for testing variation extensibility #562

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Filter the product data when variations are added in the product editor
joshuatf committed Jan 29, 2024
commit e552d77aca9c007f83854f80d17c2675a6cd8102
13 changes: 13 additions & 0 deletions assets/js/admin/admin.js
Original file line number Diff line number Diff line change
@@ -1419,4 +1419,17 @@ jQuery( function ( $ ) {
$( '.woo_subscriptions_empty_state__button_container a' ).on( 'click', function ( e ) {
$( this ).addClass( 'is-busy' );
} );

if ( window.wp.hooks && wp.data ) {
window.wp.hooks.addFilter( 'woocommerce_save_product_data', 'woocommerce-subscriptions', ( data, productId ) => {
const product = wp.data.select( 'core' ).getEditedEntityRecord( 'postType', 'product', productId );
if ( data.type === 'variable' && product.is_subscribable ) {
return {
...data,
type: 'variable-subscription'
}
}
return data;
} );
}
} );