From 91eb482e1759f97af13e65f6908609414edde3ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 24 Mar 2023 16:25:09 +0100 Subject: [PATCH] Mini-cart buttons: add explanation regarding why we need to check for children (https://github.com/woocommerce/woocommerce-blocks/pull/8847) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add comment explanation regarding the children buttons * Update comment Co-authored-by: Albert Juhé Lluveras --------- Co-authored-by: Albert Juhé Lluveras --- .../inner-blocks/mini-cart-footer-block/block.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/block.tsx b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/block.tsx index 1ce199d41a3..5c1d8c36d3c 100644 --- a/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-footer-block/block.tsx @@ -37,6 +37,9 @@ interface Props { checkoutButtonLabel: string; } +/** + * Checks if there are any children that are blocks. + */ const hasChildren = ( children ): boolean => { return children.some( ( child ) => { if ( Array.isArray( child ) ) { @@ -58,6 +61,9 @@ const Block = ( { parseInt( cartTotals.total_items_tax, 10 ) : parseInt( cartTotals.total_items, 10 ); + // The `Cart` and `Checkout` buttons were converted to inner blocks, but we still need to render the buttons + // for themes that have the old `mini-cart.html` template. So we check if there are any inner blocks (buttons) and + // if not, render the buttons. const hasButtons = hasChildren( children ); return (