微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用多个单一产品模板

如何解决使用多个单一产品模板

我目前正在使用 Sage 9 构建一个 woocommerce 网站。我正在尝试为我的每个类别创建不同的产品页面模板。我有一个分类的类别和一个自定义”类别。

现在,我尝试了两种方法

    add_filter( 'template_include','so_43621049_template_include' );

    function so_43621049_template_include( $template ) {
      if ( is_singular('product') && (has_term( 'custom','product_cat')) ) {
        $template = get_stylesheet_directory() . '/views/woocommerce/single-product-custom.blade.PHP';
      }
      return $template;
    }
    @while(have_posts())
        @PHP
            the_post();
            do_action('woocommerce_shop_loop');
            global $post;
            $terms = wp_get_post_terms( $post->ID,'product_cat' );
            foreach ( $terms as $term ) $categories[] = $term->slug;
            if ( in_array( 'custom',$categories ) ) {
            wc_get_template_part('content','single-product-custom');
            } else {
            wc_get_template_part('content','single-product');
            }
        @endPHP
    @endwhile

但没有任何作用...第一种方法没有任何作用,第二种方法做了一些奇怪的事情:当我打开自定义产品页面时,我只有页眉和页脚,页面上没有任何其他内容。这部分的 var_dump 返回以下内容

array(1) { [0]=> object(WP_Term)#13883 (10) { ["term_id"]=> int(61) ["name"]=> string(6) "Custom" ["slug"]=> string(6) "custom" ["term_group"]=> int(0) ["term_taxonomy_id"]=> int(61) ["taxonomy"]=> string(11) "product_cat" ["description"]=> string(0) "" ["parent"]=> int(0) ["count"]=> int(1) ["filter"]=> string(3) "raw" } }

我错过了什么?实现这一目标的最佳方法是什么?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。