Add to Cart with Options Block > Remove global variable overwrite. (https://github.com/woocommerce/woocommerce-blocks/pull/9457)
* Remove global variable overwrite from Add to Cart Form block. * Rename single_product to product.
This commit is contained in:
parent
6e3b1ac7fb
commit
d26936bad7
|
@ -25,23 +25,18 @@ class AddToCartForm extends AbstractBlock {
|
||||||
* @return string | void Rendered block output.
|
* @return string | void Rendered block output.
|
||||||
*/
|
*/
|
||||||
protected function render( $attributes, $content, $block ) {
|
protected function render( $attributes, $content, $block ) {
|
||||||
global $product;
|
|
||||||
|
|
||||||
$post_id = $block->context['postId'];
|
$post_id = $block->context['postId'];
|
||||||
|
|
||||||
if ( ! isset( $post_id ) ) {
|
if ( ! isset( $post_id ) ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$product = wc_get_product( $post_id );
|
||||||
if ( ! $product instanceof \WC_Product ) {
|
if ( ! $product instanceof \WC_Product ) {
|
||||||
$product = wc_get_product( $post_id );
|
return '';
|
||||||
if ( ! $product instanceof \WC_Product ) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger the single product add to cart action for each product type.
|
* Trigger the single product add to cart action for each product type.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue