dousou2897 2017-04-05 21:00
浏览 95
已采纳

如何使WooCommerce 3.0单图像库,所以它就像版本2.x?

If you updated to WooCommerce 3.0 and your theme hasn't updated as well how do you make the WooCommerce 3.0 Single Product image gallery work like the previous version?

Is is a question for themes who DO NOT copy template files and DO use conditionals, hooks, and filters to modify to avoid many issues.

  • 写回答

1条回答 默认 最新

  • dongtan4046 2017-04-05 21:00
    关注

    To add theme support for the new WooCommerce single product gallery features, you would add in your functions.php file in a child theme:

    add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support( 'wc-product-gallery-lightbox' );
    add_theme_support( 'wc-product-gallery-slider' ); 
    

    Using add_theme_support( 'wc-product-gallery-slider' ); loads FlexSlider. Without any JS issues on my end, I get is the wrong height on load when my product images are not exactly the same size. SmoothHeight is false. Even when it's turned on (via the filter), there is a large gap. All in all, on both Chrome and FireFox this issue persists.

    Therefore, an easy way to get similar functionality as 2.6 (which didn't have a slider anyway) but with the better lightbox, only add the following theme support:

    add_theme_support( 'wc-product-gallery-zoom' );
    add_theme_support( 'wc-product-gallery-lightbox' );
    

    Then filter the thumbnail images to use the shop_thumbnail size:

    /** 
     *
     * Change Thumbnail Size but run only in the @woocommerce_product_thumbnails hook
     *
     */
    function yourprefix_single_product_thumbnail_size_filter( $html, $attachment_id ){
    
            $full_size_image  = wp_get_attachment_image_src( $attachment_id, 'full' );
            $thumbnail        = wp_get_attachment_image_src( $attachment_id, 'shop_thumbnail' );
            $thumbnail_post   = get_post( $attachment_id );
            $image_title      = $thumbnail_post->post_content;
    
            $attributes = array(
                'title'                   => $image_title,
                'data-src'                => $full_size_image[0],
                'data-large_image'        => $full_size_image[0],
                'data-large_image_width'  => $full_size_image[1],
                'data-large_image_height' => $full_size_image[2],
            );
    
            $html  = '<div data-thumb="' . esc_url( $thumbnail[0] ) . '" class="woocommerce-product-gallery__image"><a href="' . esc_url( $full_size_image[0] ) . '">';
            $html .= wp_get_attachment_image( $attachment_id, 'shop_thumbnail', false, $attributes );
            $html .= '</a></div>';
    
            return $html;
    
    }
    

    Then apply it only in the woocommerce_product_thumbnails hook.

    function yourprefix_do_single_product_image_size_filter() {
    
        //apply filter
        add_filter( 'woocommerce_single_product_image_thumbnail_html', 'yourprefix_single_product_thumbnail_size_filter', 10, 4 );
    
    }
    add_action( 'woocommerce_product_thumbnails', 'yourprefix_do_single_product_image_size_filter' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?