From c8b56e4ef7c9de8548b935fd45f233d0b4c7ba85 Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Tue, 21 Nov 2023 10:26:16 +0100 Subject: [PATCH] Product Button: enqueue always the store (#11858) --- src/BlockTypes/ProductButton.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/BlockTypes/ProductButton.php b/src/BlockTypes/ProductButton.php index 353b722ab49..211e05bd10e 100644 --- a/src/BlockTypes/ProductButton.php +++ b/src/BlockTypes/ProductButton.php @@ -77,11 +77,25 @@ protected function render( $attributes, $content, $block ) { $post_id = isset( $block->context['postId'] ) ? $block->context['postId'] : ''; $product = wc_get_product( $post_id ); + wc_store( + array( + 'state' => array( + 'woocommerce' => array( + 'inTheCartText' => sprintf( + /* translators: %s: product number. */ + __( '%s in cart', 'woo-gutenberg-products-block' ), + '###' + ), + ), + ), + ) + ); + if ( $product ) { $number_of_items_in_cart = $this->get_cart_item_quantities_by_product_id( $product->get_id() ); $more_than_one_item = $number_of_items_in_cart > 0; $initial_product_text = $more_than_one_item ? sprintf( - /* translators: %s: product number. */ + /* translators: %s: product number. */ __( '%s in cart', 'woo-gutenberg-products-block' ), $number_of_items_in_cart ) : $product->add_to_cart_text(); @@ -108,20 +122,6 @@ protected function render( $attributes, $content, $block ) { ) ); - wc_store( - array( - 'state' => array( - 'woocommerce' => array( - 'inTheCartText' => sprintf( - /* translators: %s: product number. */ - __( '%s in cart', 'woo-gutenberg-products-block' ), - '###' - ), - ), - ), - ) - ); - $default_quantity = 1; $context = array(