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

Commit bf4cae4

Browse files
committed
https://github.com/woocommerce/woocommerce-blocks/pull/9581
1 parent 27393f6 commit bf4cae4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/BlockTypes/AddToCartForm.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ protected function render( $attributes, $content, $block ) {
3333
return '';
3434
}
3535

36+
$previous_product = $product;
37+
$product = wc_get_product( $post_id );
3638
if ( ! $product instanceof \WC_Product ) {
37-
$product = wc_get_product( $post_id );
38-
if ( ! $product instanceof \WC_Product ) {
39-
return '';
40-
}
39+
$product = $previous_product;
40+
41+
return '';
4142
}
4243

4344
ob_start();
@@ -52,19 +53,25 @@ protected function render( $attributes, $content, $block ) {
5253
$product = ob_get_clean();
5354

5455
if ( ! $product ) {
56+
$product = $previous_product;
57+
5558
return '';
5659
}
5760

5861
$classname = $attributes['className'] ?? '';
5962
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
6063

61-
return sprintf(
64+
$form = sprintf(
6265
'<div class="wp-block-add-to-cart-form product %1$s %2$s" style="%3$s">%4$s</div>',
6366
esc_attr( $classes_and_styles['classes'] ),
6467
esc_attr( $classname ),
6568
esc_attr( $classes_and_styles['styles'] ),
6669
$product
6770
);
71+
72+
$product = $previous_product;
73+
74+
return $form;
6875
}
6976

7077
/**

0 commit comments

Comments
 (0)