Fix: Make woocommerce/product-price available in the Single Product template (#49906)

* fix: register woocommerce/product-price using registerBlockSingleProductTemplate

* fix: remove unnecessary blockMetadata

* chore: changelog

* Enable Product Price in post editor

---------

Co-authored-by: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
This commit is contained in:
Tung Du 2024-07-24 20:58:20 +07:00 committed by GitHub
parent e39da623cf
commit ac5b051fc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 3 deletions

View File

@ -1,7 +1,7 @@
/** /**
* External dependencies * External dependencies
*/ */
import { registerBlockType } from '@wordpress/blocks'; import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils';
/** /**
* Internal dependencies * Internal dependencies
@ -28,4 +28,8 @@ const blockConfig = {
edit, edit,
}; };
registerBlockType( 'woocommerce/product-price', blockConfig ); registerBlockSingleProductTemplate( {
blockName: 'woocommerce/product-price',
blockSettings: blockConfig,
isAvailableOnPostEditor: true,
} );

View File

@ -32,7 +32,7 @@ export const registerBlockSingleProductTemplate = ( {
isAvailableOnPostEditor, isAvailableOnPostEditor,
}: { }: {
blockName: string; blockName: string;
blockMetadata: Partial< BlockConfiguration >; blockMetadata?: string | Partial< BlockConfiguration >;
blockSettings: Partial< BlockConfiguration >; blockSettings: Partial< BlockConfiguration >;
isAvailableOnPostEditor: boolean; isAvailableOnPostEditor: boolean;
isVariationBlock?: boolean; isVariationBlock?: boolean;
@ -40,6 +40,10 @@ export const registerBlockSingleProductTemplate = ( {
} ) => { } ) => {
let currentTemplateId: string | undefined = ''; let currentTemplateId: string | undefined = '';
if ( ! blockMetadata ) {
blockMetadata = blockName;
}
subscribe( () => { subscribe( () => {
const previousTemplateId = currentTemplateId; const previousTemplateId = currentTemplateId;
const store = select( 'core/edit-site' ); const store = select( 'core/edit-site' );

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Fix: Make woocommerce/product-price available in the Single Product template