Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Product Button: enqueue always the store (#11858)
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux authored and wavvves committed Nov 21, 2023
1 parent cc097a8 commit c8b56e4
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/BlockTypes/ProductButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down

0 comments on commit c8b56e4

Please sign in to comment.