From ac5b051fc2e6390dfd12886103f97a52fd6d5095 Mon Sep 17 00:00:00 2001 From: Tung Du Date: Wed, 24 Jul 2024 20:58:20 +0700 Subject: [PATCH] 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> --- .../js/atomic/blocks/product-elements/price/index.tsx | 8 ++++++-- .../utils/register-block-single-product-template.ts | 6 +++++- .../fix-register-product-price-using-custom-method | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-register-product-price-using-custom-method diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx index 4fce83f49fd..3dd27385f03 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/price/index.tsx @@ -1,7 +1,7 @@ /** * External dependencies */ -import { registerBlockType } from '@wordpress/blocks'; +import { registerBlockSingleProductTemplate } from '@woocommerce/atomic-utils'; /** * Internal dependencies @@ -28,4 +28,8 @@ const blockConfig = { edit, }; -registerBlockType( 'woocommerce/product-price', blockConfig ); +registerBlockSingleProductTemplate( { + blockName: 'woocommerce/product-price', + blockSettings: blockConfig, + isAvailableOnPostEditor: true, +} ); diff --git a/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts b/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts index 87784a0011c..58f842c362d 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts +++ b/plugins/woocommerce-blocks/assets/js/atomic/utils/register-block-single-product-template.ts @@ -32,7 +32,7 @@ export const registerBlockSingleProductTemplate = ( { isAvailableOnPostEditor, }: { blockName: string; - blockMetadata: Partial< BlockConfiguration >; + blockMetadata?: string | Partial< BlockConfiguration >; blockSettings: Partial< BlockConfiguration >; isAvailableOnPostEditor: boolean; isVariationBlock?: boolean; @@ -40,6 +40,10 @@ export const registerBlockSingleProductTemplate = ( { } ) => { let currentTemplateId: string | undefined = ''; + if ( ! blockMetadata ) { + blockMetadata = blockName; + } + subscribe( () => { const previousTemplateId = currentTemplateId; const store = select( 'core/edit-site' ); diff --git a/plugins/woocommerce/changelog/fix-register-product-price-using-custom-method b/plugins/woocommerce/changelog/fix-register-product-price-using-custom-method new file mode 100644 index 00000000000..3aa5d4e0505 --- /dev/null +++ b/plugins/woocommerce/changelog/fix-register-product-price-using-custom-method @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix: Make woocommerce/product-price available in the Single Product template