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

Commit fe6f0eb

Browse files
Aljullugigitux
authored andcommitted
Fix images hidden by default in Product grid blocks (#6599)
1 parent cc61e6b commit fe6f0eb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

assets/js/editor-components/grid-content-control/index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import { ToggleControl } from '@wordpress/components';
1414
*/
1515
const GridContentControl = ( { onChange, settings } ) => {
1616
const { image, button, price, rating, title } = settings;
17+
// If `image` is undefined, that might be because it's a block that was
18+
// created before the `image` attribute existed, so we default to true.
19+
const imageIsVisible = image !== false;
1720
return (
1821
<>
1922
<ToggleControl
2023
label={ __( 'Product image', 'woo-gutenberg-products-block' ) }
2124
help={
22-
image
25+
imageIsVisible
2326
? __(
2427
'Product image is visible.',
2528
'woo-gutenberg-products-block'
@@ -29,8 +32,10 @@ const GridContentControl = ( { onChange, settings } ) => {
2932
'woo-gutenberg-products-block'
3033
)
3134
}
32-
checked={ image }
33-
onChange={ () => onChange( { ...settings, image: ! image } ) }
35+
checked={ imageIsVisible }
36+
onChange={ () =>
37+
onChange( { ...settings, image: ! imageIsVisible } )
38+
}
3439
/>
3540
<ToggleControl
3641
label={ __( 'Product title', 'woo-gutenberg-products-block' ) }

src/BlockTypes/AbstractProductGrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ protected function render_product( $product ) {
519519
* @return string
520520
*/
521521
protected function get_image_html( $product ) {
522-
if ( empty( $this->attributes['contentVisibility']['image'] ) ) {
522+
if ( array_key_exists( 'image', $this->attributes['contentVisibility'] ) && false === $this->attributes['contentVisibility']['image'] ) {
523523
return '';
524524
}
525525

0 commit comments

Comments
 (0)