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

Commit

Permalink
add support for the custom classname
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Jan 31, 2023
1 parent 90c71d3 commit bfd2e98
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
*/
import { useBlockProps } from '@wordpress/block-editor';

export const Save = (): JSX.Element => {
return <div { ...useBlockProps.save() } />;
type Props = {
attributes: Record< string, unknown > & {
className?: string;
};
};

export const Save = ( { attributes }: Props ): JSX.Element => {
return (
<div
{ ...useBlockProps.save( {
className: attributes.className,
} ) }
/>
);
};

export default Save;
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export const registerBlockSingleProductTemplate = ( {
if ( block !== undefined ) {
unregisterBlockFn();
}
} );
}, 'test' );
};
7 changes: 2 additions & 5 deletions src/BlockTypes/ProductImageGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,15 @@ protected function render( $attributes, $content, $block ) {
$frontend_scripts::load_scripts();
}

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

ob_start();
woocommerce_show_product_images();
$product_image_gallery_html = ob_get_clean();

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

Expand Down

0 comments on commit bfd2e98

Please sign in to comment.