Site logo

Archived topic

Problema con plugin

18 replies · Started by Pedro on June 11, 2021

Viewing posts 16–19 of 19

Hola Tom,

Por defecto, cada variación solo tiene una imagen (Es como funciona WooCommerce).

Por esta razón es que prefiero usar el plugin "WooCommerce Additional Variation Images".

Enlace del plugin: https://woocommerce.com/es-es/products/woocommerce-additional-variation-images/

Sin embargo, ese plugin en este momento está desactivado para hacer pruebas.

Ahora, independientemente de que las variaciones solo tienen una imagen, heredan las demás imágenes del producto principal.

Aquí hay un ejemplo, en donde he escogido la variación de color "Blanco", y la primera imagen muestra la camiseta blanca, pero las demás imágenes que muestra son las del producto principal.

Ver captura de pantalla: https://mega.nz/file/S0VVXKLB#VJwoOATNqv1pyro77090Dp255R8BcvsVoxb31O6fpO4

Entonces, ahí es donde digo que GeneratePress debería mostrar la imagen secundaria del producto principal.

Hmm, let's try this:

add_action( 'woocommerce_before_shop_loop_item_title', function() {
    $post_type = get_post_type( get_the_ID() );

    if ( method_exists( 'WC_Product', 'get_gallery_image_ids' ) ) {
        $variation = wc_get_product( get_the_ID() );

        if ( $variation->get_parent_id() ) {
            $product = wc_get_product( $variation->get_parent_id() );
            $attachment_ids = $product->get_gallery_image_ids();

            if ( $attachment_ids && generatepress_wc_get_setting( 'product_secondary_image' ) && generatepress_wc_get_setting( 'product_archive_image' ) && has_post_thumbnail() ) {
                $secondary_image_id = $attachment_ids['0'];
                echo wp_get_attachment_image( $secondary_image_id, 'shop_catalog', '', $attr = array( 'class' => 'secondary-image attachment-shop-catalog' ) );
            }
        }
    }
} );

Let me know if it works or not :)

Hola Tom,

He agregado el nuevo código y ahora las variaciones están mostrando la imagen secundaria del producto principal.

Ahora bien, he activado nuevamente el plugin "WooCommerce Additional Variation Images" para probar si funcionaba.

Lo que ocurre es que si muestra la imagen secundaria, pero del producto principal.

Por ejemplo, la camiseta blanca al hacer hover, muestra la imagen de la camiseta negra (Producto principal).

¿Habrá forma de corregir esto?

For example, the white t-shirt when hovering, displays the image of the black t-shirt (Main Product).

The code looks in the main product and grabs the first image from the gallery. We would need to tweak the function to grab the correct image, but that's where this gets difficult. How do we get the necessary image using PHP? This is likely a question for the developers of that plugin.

This archived topic is closed to new replies.