使用多个单一产品模板

问题描述

我目前正在使用 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 (将#修改为@)