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' );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 Hyper-v虚拟机相关问题,求解答。
  • ¥15 TSM320F2808PZA芯片 Bootloader
  • ¥45 谷歌浏览器出现开发者工具无法显示已创建的,但您可以调试已部署的代码。 状态代码 404, net::ERR HTTP RESPONSE CODE FAILURE
  • ¥15 chatgpt网页版侧边栏和模型切换点击没反应怎么办
  • ¥15 如何解决蓝牙通话音频突发失真问题
  • ¥15 安装opengauss数据库报错
  • ¥15 【急】在线问答CNC雕刻机的电子电路与编程
  • ¥60 在mc68335芯片上移植ucos ii 的成功工程文件
  • ¥15 笔记本外接显示器正常,但是笔记本屏幕黑屏
  • ¥15 Python pandas