From 241984a2655ec937daf6ef20427677733e6f1f2d Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 27 Sep 2023 12:56:24 +0100 Subject: [PATCH] Fix downloads block visibility (https://github.com/woocommerce/woocommerce-blocks/pull/11056) --- .../downloads-wrapper/edit.tsx | 17 ++++++++++++----- .../downloads-wrapper/editor.scss | 3 +++ .../order-confirmation/totals-wrapper/edit.tsx | 8 -------- .../src/BlockTypesController.php | 8 ++++++++ 4 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 plugins/woocommerce-blocks/assets/js/blocks/order-confirmation/downloads-wrapper/editor.scss diff --git a/plugins/woocommerce-blocks/assets/js/blocks/order-confirmation/downloads-wrapper/edit.tsx b/plugins/woocommerce-blocks/assets/js/blocks/order-confirmation/downloads-wrapper/edit.tsx index 7b5d1a43649..630886fa283 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/order-confirmation/downloads-wrapper/edit.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/order-confirmation/downloads-wrapper/edit.tsx @@ -3,6 +3,12 @@ */ import { useBlockProps, InnerBlocks } from '@wordpress/block-editor'; import { getSetting } from '@woocommerce/settings'; +import classnames from 'classnames'; + +/** + * Internal dependencies + */ +import './editor.scss'; const Edit = ( { attributes, @@ -18,12 +24,13 @@ const Edit = ( { 'storeHasDownloadableProducts' ); - if ( ! hasDownloadableProducts ) { - return null; - } - return ( -
+
) => void; } ) => { const blockProps = useBlockProps(); - const hasDownloadableProducts = getSetting( - 'storeHasDownloadableProducts' - ); - - if ( ! hasDownloadableProducts ) { - return null; - } return (
diff --git a/plugins/woocommerce-blocks/src/BlockTypesController.php b/plugins/woocommerce-blocks/src/BlockTypesController.php index 7ae60ccf2b7..0d724995f54 100644 --- a/plugins/woocommerce-blocks/src/BlockTypesController.php +++ b/plugins/woocommerce-blocks/src/BlockTypesController.php @@ -51,6 +51,7 @@ final class BlockTypesController { add_filter( 'render_block', array( $this, 'add_data_attributes' ), 10, 2 ); add_action( 'woocommerce_login_form_end', array( $this, 'redirect_to_field' ) ); add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_legacy_widgets_with_block_equivalent' ) ); + add_action( 'woocommerce_delete_product_transients', array( $this, 'delete_product_transients' ) ); } /** @@ -159,6 +160,13 @@ final class BlockTypesController { return $widget_types; } + /** + * Delete product transients when a product is deleted. + */ + public function delete_product_transients() { + delete_transient( 'wc_blocks_has_downloadable_product' ); + } + /** * Get list of block types. *