diff --git a/plugins/woocommerce/changelog/fix-add-extra-css-classes-to-product-image b/plugins/woocommerce/changelog/fix-add-extra-css-classes-to-product-image
new file mode 100644
index 00000000000..54b208d6aa3
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-add-extra-css-classes-to-product-image
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Render Advanced CSS Classes in the Product Image block
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartForm.php b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartForm.php
index e2c02850e3f..8b8aa44c6fc 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartForm.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/AddToCartForm.php
@@ -99,14 +99,12 @@ class AddToCartForm extends AbstractBlock {
$product = $this->add_is_descendent_of_single_product_block_hidden_input_to_product_form( $product, $is_descendent_of_single_product_block );
}
- $classname = $attributes['className'] ?? '';
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
$product_classname = $is_descendent_of_single_product_block ? 'product' : '';
$form = sprintf(
- '
-
- %4$s
+ '
',
esc_attr( $classes_and_styles['classes'] ),
- esc_attr( $classname ),
esc_attr( $classes_and_styles['styles'] ),
$tabs
);
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php
index 9d52abacc8a..0ecdea898b0 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGallery.php
@@ -3,6 +3,7 @@ namespace Automattic\WooCommerce\Blocks\BlockTypes;
use Automattic\WooCommerce\Blocks\Utils\BlockTemplateUtils;
use Automattic\WooCommerce\Blocks\Utils\ProductGalleryUtils;
+use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
/**
* ProductGallery class.
@@ -125,7 +126,7 @@ class ProductGallery extends AbstractBlock {
}
$number_of_thumbnails = $block->attributes['thumbnailsNumberOfThumbnails'] ?? 0;
- $classname = $attributes['className'] ?? '';
+ $classname = StyleAttributesUtils::get_classes_by_attributes( $attributes, array( 'extra_classes' ) );
$dialog = isset( $attributes['mode'] ) && 'full' !== $attributes['mode'] ? $this->render_dialog() : '';
$product_gallery_first_image = ProductGalleryUtils::get_product_gallery_image_ids( $product, 1 );
$product_gallery_first_image_id = reset( $product_gallery_first_image );
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryPager.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryPager.php
index 58e268addc0..ac478cc71c0 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryPager.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductGalleryPager.php
@@ -2,6 +2,7 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes;
use Automattic\WooCommerce\Blocks\Utils\ProductGalleryUtils;
+use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
/**
* ProductGalleryPager class.
@@ -55,7 +56,7 @@ class ProductGalleryPager extends AbstractBlock {
}
$number_of_thumbnails = $block->context['thumbnailsNumberOfThumbnails'] ?? 0;
- $classname = $attributes['className'] ?? '';
+ $classname = StyleAttributesUtils::get_classes_by_attributes( $attributes, array( 'extra_classes' ) );
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => trim( $classname ) ) );
$post_id = $block->context['postId'] ?? '';
$product = wc_get_product( $post_id );
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php
index 2c08524fdc0..98dc66b40ed 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductImageGallery.php
@@ -1,6 +1,8 @@
%2$s %3$s
',
esc_attr( $classname ),
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php
index 61bbe35fdd1..aa5e8b20e8a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductResultsCount.php
@@ -54,7 +54,6 @@ class ProductResultsCount extends AbstractBlock {
'wc-block-product-results-count',
'wp-block-woocommerce-product-results-count',
),
- isset( $attributes['className'] ) ? array( $attributes['className'] ) : array(),
);
$p->set_attribute( 'class', implode( ' ', $classes ) );
$p->set_attribute( 'style', $parsed_style_attributes['styles'] );
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductReviews.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductReviews.php
index 8675cdc2709..719c9dc758a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductReviews.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductReviews.php
@@ -2,6 +2,8 @@
namespace Automattic\WooCommerce\Blocks\BlockTypes;
+use Automattic\WooCommerce\Blocks\Utils\StyleAttributesUtils;
+
/**
* ProductReviews class.
*/
@@ -40,13 +42,11 @@ class ProductReviews extends AbstractBlock {
$reviews = ob_get_clean();
- $classname = $attributes['className'] ?? '';
-
return sprintf(
'
%2$s
',
- esc_attr( $classname ),
+ StyleAttributesUtils::get_classes_by_attributes( $attributes, array( 'extra_classes' ) ),
$reviews
);
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php
index 5bd428d21e2..b7e958bd43a 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductSaleBadge.php
@@ -110,8 +110,9 @@ class ProductSaleBadge extends AbstractBlock {
return null;
}
- $classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
- $classname = isset( $attributes['className'] ) ? $attributes['className'] : '';
+ $classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array(), array( 'extra_classes' ) );
+
+ $classname = StyleAttributesUtils::get_classes_by_attributes( $attributes, array( 'extra_classes' ) );
$align = isset( $attributes['align'] ) ? $attributes['align'] : '';
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php b/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php
index 867d6d9d50a..0bc742e2336 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/ProductStockIndicator.php
@@ -101,7 +101,6 @@ class ProductStockIndicator extends AbstractBlock {
$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );
$classnames = isset( $classes_and_styles['classes'] ) ? ' ' . $classes_and_styles['classes'] . ' ' : '';
- $classnames .= isset( $attributes['className'] ) ? ' ' . $attributes['className'] . ' ' : '';
$classnames .= ! $is_in_stock ? ' wc-block-components-product-stock-indicator--out-of-stock ' : '';
$classnames .= $is_in_stock ? ' wc-block-components-product-stock-indicator--in-stock ' : '';
$classnames .= $is_low_stock ? ' wc-block-components-product-stock-indicator--low-stock ' : '';
diff --git a/plugins/woocommerce/src/Blocks/Utils/StyleAttributesUtils.php b/plugins/woocommerce/src/Blocks/Utils/StyleAttributesUtils.php
index 5205dcc3691..ce5894ce1c9 100644
--- a/plugins/woocommerce/src/Blocks/Utils/StyleAttributesUtils.php
+++ b/plugins/woocommerce/src/Blocks/Utils/StyleAttributesUtils.php
@@ -687,6 +687,25 @@ class StyleAttributesUtils {
return self::EMPTY_STYLE;
}
+ /**
+ * Get extra CSS classes from attributes.
+ *
+ * @param array $attributes Block attributes.
+ * @return array
+ */
+ public static function get_classes_from_attributes( $attributes ) {
+
+ $extra_css_classes = $attributes['className'] ?? '';
+
+ if ( '' !== $extra_css_classes ) {
+ return array(
+ 'class' => $extra_css_classes,
+ 'style' => null,
+ );
+ }
+ return self::EMPTY_STYLE;
+ }
+
/**
* Get classes and styles from attributes.
*
@@ -717,6 +736,7 @@ class StyleAttributesUtils {
'text_color' => self::get_text_color_class_and_style( $attributes ),
'text_decoration' => self::get_text_decoration_class_and_style( $attributes ),
'text_transform' => self::get_text_transform_class_and_style( $attributes ),
+ 'extra_classes' => self::get_classes_from_attributes( $attributes ),
);
if ( ! empty( $properties ) ) {