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

Commit

Permalink
https://github.com/woocommerce/woocommerce-blocks/pull/9581
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed May 24, 2023
1 parent 27393f6 commit bf4cae4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/BlockTypes/AddToCartForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ protected function render( $attributes, $content, $block ) {
return '';
}

$previous_product = $product;
$product = wc_get_product( $post_id );
if ( ! $product instanceof \WC_Product ) {
$product = wc_get_product( $post_id );
if ( ! $product instanceof \WC_Product ) {
return '';
}
$product = $previous_product;

return '';
}

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

if ( ! $product ) {
$product = $previous_product;

return '';
}

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

return sprintf(
$form = sprintf(
'<div class="wp-block-add-to-cart-form product %1$s %2$s" style="%3$s">%4$s</div>',
esc_attr( $classes_and_styles['classes'] ),
esc_attr( $classname ),
esc_attr( $classes_and_styles['styles'] ),
$product
);

$product = $previous_product;

return $form;
}

/**
Expand Down

0 comments on commit bf4cae4

Please sign in to comment.