WooCommerce产品图片放大

问题描述 投票:0回答:1

我目前正在开发一个支持WooCommerce的Wordpress网站。我已经创建了一个产品,并且已经为图库上​​传了精选图片和其他照片。但是有一个问题我无法弄清楚。无论照片有多大都没关系,如果我把光标放在它上面,它会变焦近200%,这太过分了。有谁知道如何减少(或删除)缩放功能?我去过“sinlge-product / product-image.php”,但似乎我在代码中找不到任何缩放选项:

    <?php
/**
 * Single Product Image
 *
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     2.0.14
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}

global $post, $woocommerce, $product;

?>

<div class="images">

    <?php
        if ( has_post_thumbnail() ) {

            $image_title    = esc_attr( get_the_title( get_post_thumbnail_id() ) );
            $image_caption  = get_post( get_post_thumbnail_id() )->post_excerpt;
            $image_link     = wp_get_attachment_url( get_post_thumbnail_id() );
            $image          = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array(
                'title' => $image_title,
                'alt'   => $image_title
                ) );

            $attachment_count = count( $product->get_gallery_attachment_ids() );

            if ( $attachment_count > 0 ) {
                $gallery = '[product-gallery]';
            } else {
                $gallery = '';
            }



        } else {

            echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="%s" />', wc_placeholder_img_src(), __( 'Placeholder', 'woocommerce' ) ), $post->ID );

        }
    ?>

    <?php do_action( 'woocommerce_product_thumbnails' ); ?>

</div>

谢谢!

wordpress woocommerce
1个回答
0
投票

将此代码复制/粘贴到您的子主题的functions.php。经过测试和批准;)

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
add_filter( 'woocommerce_gallery_full_size', 'change_magnifier_lightbox_image_size', 20, 1 );
function change_magnifier_lightbox_image_size( $size ){
    $thumbnail_id = get_post_thumbnail_id( get_the_id() );
    $attachment   = wp_get_attachment_metadata( $thumbnail_id, FALSE );

    // Always return a value in a filter hook
    return ( $attachment['width'] > 3071 || $attachment['height'] > 3071 ) ? 'preview' : 'large';
}
© www.soinside.com 2019 - 2024. All rights reserved.