首页 文章

在商店存档页面上激活Woocommerce图库功能

提问于
浏览
0

我正在尝试 Build 一个Woocommerce商店,所有产品都列在商店档案页面上,其中包含完整的产品信息(摘录,图片, Headers ,价格等) . 没有产品详情页面 .

我已经在我的theme / woocommerce文件夹中的自定义archive-product.php的循环中加载了简单页面内容而不是页面内容 .

我的问题是,产品图库的功能(缩放,灯箱,滑块)不能在存档页面上工作,只能在单个产品页面上工作 .

如何解锁商店和类别存档页面的图库功能?

我认为,wordpress或woocommerce以某种方式停用了此页面上的图库功能的某些javascript或php函数 . 但我无法弄清楚在哪里进行更改以便将它们带回来 .

这是我在moded archive-product.php中用于循环的代码 . 我只是将“产品”更改为“单一产品”,以便加载完整的产品内容:

<?php while ( have_posts() ) : the_post(); ?>

    <?php
        /**
        * woocommerce_shop_loop hook.
        *
        * @hooked WC_Structured_Data::generate_product_data() - 10
        */
    do_action( 'woocommerce_shop_loop' );
    ?>

    <!-- This part of the template has been moded for the product archive page to show the complete content of the single product page -->

    <?php wc_get_template_part( 'content', 'single-product' ); ?>

<?php endwhile; // end of the loop. ?>

1 回答

  • 0

    如果有人遇到与我相同的问题,并希望激活存档页面上与产品页面相同的woocommerce图库功能,请将此代码添加到主题文件夹中的functions.php:

    add_action( 'wp_enqueue_scripts', 'gallery_scripts', 20 );
    
    function gallery_scripts() {
        if ( is_archive()) {
            if ( current_theme_supports( 'wc-product-gallery-zoom' ) ) { 
                wp_enqueue_script( 'zoom' );
            }
            if ( current_theme_supports( 'wc-product-gallery-slider' ) ) {
                wp_enqueue_script( 'flexslider' );
            }
            if ( current_theme_supports( 'wc-product-gallery-lightbox' ) ) {
                wp_enqueue_script( 'photoswipe-ui-default' );
                wp_enqueue_style( 'photoswipe-default-skin' );
                add_action( 'wp_footer', 'woocommerce_photoswipe' );
            }
            wp_enqueue_script( 'wc-single-product' );
        }
    
    }
    

相关问题