Commit 215b50531a for woocommerce
commit 215b50531a1d831761e89bb27fae45b7bfc43b3a
Author: Michael Pretty <prettyboymp@users.noreply.github.com>
Date: Mon Jan 12 14:10:39 2026 -0500
Replace get_available_variations() with get_visible_children() in product-image.php (#62754)
Replace get_available_variations() with more efficient checks in product-image.php
diff --git a/plugins/woocommerce/changelog/fix-wooplug-6119-replace-get-available-variations-product-image b/plugins/woocommerce/changelog/fix-wooplug-6119-replace-get-available-variations-product-image
new file mode 100644
index 0000000000..730ff0bcad
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-wooplug-6119-replace-get-available-variations-product-image
@@ -0,0 +1,4 @@
+Significance: patch
+Type: performance
+
+Replace get_available_variations() with get_visible_children() and get_price() in product-image.php template for better performance.
\ No newline at end of file
diff --git a/plugins/woocommerce/templates/single-product/product-image.php b/plugins/woocommerce/templates/single-product/product-image.php
index 751eea371d..9693c7174c 100644
--- a/plugins/woocommerce/templates/single-product/product-image.php
+++ b/plugins/woocommerce/templates/single-product/product-image.php
@@ -12,7 +12,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
- * @version 9.7.0
+ * @version 10.5.0
*/
use Automattic\WooCommerce\Enums\ProductType;
@@ -44,7 +44,10 @@ $wrapper_classes = apply_filters(
if ( $post_thumbnail_id ) {
$html = wc_get_gallery_image_html( $post_thumbnail_id, true );
} else {
- $wrapper_classname = $product->is_type( ProductType::VARIABLE ) && ! empty( $product->get_available_variations( 'image' ) ) ?
+ // Check for visible children with prices to determine if variation image swapping is possible.
+ // Using get_visible_children() + get_price() is more efficient than get_available_variations()
+ // as it uses cached IDs and synced price data rather than loading all variation objects.
+ $wrapper_classname = $product->is_type( ProductType::VARIABLE ) && ! empty( $product->get_visible_children() ) && '' !== $product->get_price() ?
'woocommerce-product-gallery__image woocommerce-product-gallery__image--placeholder' :
'woocommerce-product-gallery__image--placeholder';
$html = sprintf( '<div class="%s">', esc_attr( $wrapper_classname ) );