get_id() ] ) ) { return $parsed_block; } $primed[ $product->get_id() ] = true; $children = $product->is_type( 'variable' ) ? array_map( 'intval', (array) $product->get_children() ) : array(); if ( $children ) { update_meta_cache( 'post', $children ); } $ids = array_merge( array( (int) $product->get_image_id() ), array_map( 'intval', (array) $product->get_gallery_image_ids() ) ); foreach ( $children as $child ) { $ids[] = (int) get_post_meta( $child, '_thumbnail_id', true ); $ids = array_merge( $ids, array_map( 'intval', array_filter( explode( ',', (string) get_post_meta( $child, '_product_image_gallery', true ) ) ) ) ); } $ids = array_values( array_unique( array_filter( $ids ) ) ); if ( $ids && function_exists( '_prime_post_caches' ) ) { _prime_post_caches( $ids, false, true ); } return $parsed_block; } public static function block_gallery_seen( $html ) { self::$block_gallery = true; return $html; } public static function feature_enabled() { $pkg = '\Automattic\WooCommerce\Internal\VariationGallery\Package'; if ( class_exists( $pkg ) && is_callable( array( $pkg, 'is_enabled' ) ) ) { try { return (bool) $pkg::is_enabled(); } catch ( \Throwable $e ) { } } if ( defined( 'WC_VERSION' ) && version_compare( (string) WC_VERSION, '11.1', '>=' ) ) { return true; } $util = '\Automattic\WooCommerce\Utilities\FeaturesUtil'; if ( class_exists( $util ) && method_exists( $util, 'feature_is_enabled' ) ) { return (bool) $util::feature_is_enabled( 'variation_gallery' ); } return 'yes' === get_option( 'woocommerce_feature_variation_gallery_enabled', 'no' ); } public static function fill( $data, $parent, $variation ) { if ( ! is_array( $data ) || ! is_object( $parent ) || ! is_object( $variation ) ) { return $data; } if ( ! array_key_exists( 'gallery_image_ids', $data ) ) { return $data; } if ( ! self::feature_enabled() || self::$block_gallery ) { return $data; } if ( ! empty( $data['gallery_image_ids'] ) ) { return $data; } $ids = array(); $own = method_exists( $variation, 'get_image_id' ) ? (int) $variation->get_image_id() : 0; if ( $own && wp_attachment_is_image( $own ) ) { $ids[] = $own; } $hero = method_exists( $parent, 'get_image_id' ) ? (int) $parent->get_image_id() : 0; if ( $hero && wp_attachment_is_image( $hero ) && ! in_array( $hero, $ids, true ) ) { $ids[] = $hero; } foreach ( (array) $parent->get_gallery_image_ids() as $gid ) { $gid = (int) $gid; if ( $gid && wp_attachment_is_image( $gid ) && ! in_array( $gid, $ids, true ) ) { $ids[] = $gid; } } if ( ! $ids ) { return $data; } $data['gallery_image_ids'] = $ids; $data['gallery_images_html'] = function_exists( 'wc_get_product_gallery_html' ) ? wc_get_product_gallery_html( $parent, $ids ) : $data['gallery_images_html']; return $data; } }