diff --git a/plugins/woocommerce-blocks/src/BlockTypes/ProductGallery.php b/plugins/woocommerce-blocks/src/BlockTypes/ProductGallery.php index 46c124c708f..0f4e2c30dfd 100644 --- a/plugins/woocommerce-blocks/src/BlockTypes/ProductGallery.php +++ b/plugins/woocommerce-blocks/src/BlockTypes/ProductGallery.php @@ -24,6 +24,27 @@ class ProductGallery extends AbstractBlock { return [ 'postId' ]; } + /** + * Inject dialog into the product gallery HTML. + * + * @param string $gallery_html The gallery HTML. + * @param string $dialog_html The dialog HTML. + * + * @return string + */ + protected function inject_dialog( $gallery_html, $dialog_html ) { + + // Find the position of the last . + $pos = strrpos( $gallery_html, '' ); + + if ( false !== $pos ) { + // Inject the dialog_html at the correct position. + $html = substr_replace( $gallery_html, $dialog_html, $pos, 0 ); + + return $html; + } + } + /** * Return the dialog content. * @@ -48,21 +69,6 @@ class ProductGallery extends AbstractBlock { return $gallery_dialog; } - - /** - * This function remove the div wrapper. - * The content has a
with the class wp-block-woocommerce-product-gallery>. - * We don't need since that we add it in the render method. - * - * @param string $content Block content. - * @return string Rendered block type output. - */ - private function remove_div_wrapper( $content ) { - $parsed_string = preg_replace( '/