【发布时间】:2018-11-08 13:44:44
【问题描述】:
我是 Woocommerce 的新手。我想为书籍类别自定义 Woocommerce 产品页面的模板。我用自定义文件替换了 content-single-product.php 文件,修改了 single-product.php 文件中的代码,如下所示:
<?php while ( have_posts() ) : the_post(); ?>
<?php
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
if ( in_array( 'livros', $categories ) ) {
wc_get_template_part( 'content', 'single-product-books' );
} else {
wc_get_template_part( 'content', 'single-product' );
}
?>
<?php endwhile; // end of the loop. ?>
现在我想用这个 product-image-books.php 替换 product-image.php 文件。像这样尝试但不起作用:
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
if ( in_array( 'books', $categories ) ) {
wc_get_template_part( 'content', 'single-product-books' );
wc_get_template_part( 'single-product/product', 'image-books' );
} else {
wc_get_template_part( 'content', 'single-product' );
wc_get_template_part( 'content', 'product-image' );
}
?>
此文件位于模板文件夹中:woocommerce > single-product.有什么帮助吗?
【问题讨论】:
标签: wordpress woocommerce