Add zoom and flex slider functionatility gallery images for variable products with missing Product Image (#47714)

* Add zoom functionatility to Single Product gallery images when main Product Image is missing

* Alternative approach

* Add changelog file

* Still add placeholder class for extra backwards compatibility

* Bump template version

* Remove unnecessary class name change

* Fix wrong type
This commit is contained in:
Albert Juhé Lluveras 2024-05-30 10:41:05 +02:00 committed by GitHub
parent c6424c09d1
commit 712ffa3381
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: enhancement
If a variable product doesn't have a Product Image but variations do have images, the zoom and flex slider will be initiated as expected

View File

@ -12,7 +12,7 @@
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 7.8.0
* @version 9.0.0
*/
defined( 'ABSPATH' ) || exit;
@ -42,7 +42,10 @@ $wrapper_classes = apply_filters(
if ( $post_thumbnail_id ) {
$html = wc_get_gallery_image_html( $post_thumbnail_id, true );
} else {
$html = '<div class="woocommerce-product-gallery__image--placeholder">';
$wrapper_classname = $product->is_type( 'variable' ) && ! empty( $product->get_available_variations( 'image' ) ) ?
'woocommerce-product-gallery__image woocommerce-product-gallery__image--placeholder' :
'woocommerce-product-gallery__image--placeholder';
$html = sprintf( '<div class="%s">', esc_attr( $wrapper_classname ) );
$html .= sprintf( '<img src="%s" alt="%s" class="wp-post-image" />', esc_url( wc_placeholder_img_src( 'woocommerce_single' ) ), esc_html__( 'Awaiting product image', 'woocommerce' ) );
$html .= '</div>';
}