Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Woocommerce内容单一产品模板覆盖无效_Php_Woocommerce - Fatal编程技术网

Php Woocommerce内容单一产品模板覆盖无效

Php Woocommerce内容单一产品模板覆盖无效,php,woocommerce,Php,Woocommerce,我有一个问题,从昨天起我就一直在努力解决。所以,我有woocommerce网站,它仍然在本地主机上。 我对模板覆盖有问题。我在我的主题中覆盖了循环start、end、content-product.php和content-single-product.php,这一切正常。 我对content-single-product.php有问题,因为我想让它在类别上可靠(无论标识是什么——id、name、slug)。所以我在谷歌上发现了一些解决方案,但没有一个能奏效。 在我的singe-product.p

我有一个问题,从昨天起我就一直在努力解决。所以,我有woocommerce网站,它仍然在本地主机上。 我对模板覆盖有问题。我在我的主题中覆盖了循环start、end、content-product.php和content-single-product.php,这一切正常。 我对content-single-product.php有问题,因为我想让它在类别上可靠(无论标识是什么——id、name、slug)。所以我在谷歌上发现了一些解决方案,但没有一个能奏效。 在我的singe-product.php中,我替换了

 woocommerce_get_template_part( 'content', 'single-product' );

我试着用
代替我的猫鼻涕虫实际的猫名!产品类别是否要反。。。也没什么。
当然,我把single-product.php放在我的主题中的woocommerce文件夹中,其余的工作覆盖文件都在其中。我创建了content-single-product-dogs.php文件,在这里我复制了content-single-product.php中的内容,并做了一些修改,就像这里编写的测试一样小

我也试过了

if ( ! function_exists( 'woocommerce_content' ) ) {
    function woocommerce_content() {
        if ( has_term( 'my-cat-slug', 'product_cat' ) ) {
            while ( have_posts() ) : the_post();
                wc_get_template_part( 'content', 'single-product-dogs' );
            endwhile;
        }
        else {
            while ( have_posts() ) : the_post();
                wc_get_template_part( 'content', 'single-product' );
            endwhile;
        }
    }
}
那也不行。无论我使用什么,它都会返回到默认覆盖的content-single-product.php

我没有更多的想法。请有人帮忙:)

另外,是否可以更改默认的product-image.php,使其与自定义内容single-product-dog.php不同


谢谢

如果您的主题中已有WooCommerce,您可以覆盖WooCommerce\u content()功能

它在WooCommerce 2.5.5上运行得非常好

  • 将您的自定义模板文件放置到您的主题/woocommerce/

  • 将下面列出的代码片段添加到主题functions.php

/**
*覆盖“内容”功能
*/
如果(!function_存在('woocommerce_content')){
/**
*输出商业内容。
*
*此函数仅在可选的“woocommerce.php”模板中使用。
*人们可以添加到他们的主题中,以添加基本的商业支持。
*没有挂钩或修改核心模板。
*
*/
功能和内容(){
if(是单数('product')){
while(have_posts()):the_post();
//模板依赖于类别slug
如果(有术语(“我的猫鼻涕虫”、“产品猫”)){
woocommerce_get_template_part('content','single product dogs');
}否则{
woocommerce_get_template_part(‘内容’、‘单一产品’);
}
结束时;
}还有{?>

您的woocommerce版本是什么?
woocommerce\u get\u template\u part
在当前版本中已被弃用。它是最新的。最新版本。aaah所以它不是woocommerce\u get..而是wc\u get。将尝试并测试使用
的术语('my cat slug','product\u cat'))
在第一次尝试时,代码..
是产品类别
是当您查看产品类别页面时…不会检查产品是否有类别…谢谢,也不起作用。嗯,但是当我放置纯商业模板部分('content','single product dogs')时;仅仅是itslef,所以它应该使用content-single-product-dogs.php,它仍然没有任何效果。它类似于single-product.php覆盖被忽略。真的是wierd,它是在woocommerce内部主题中。嘿,我也准备好解决这个问题了。但是我把你的答案标记为最接近。这件事与woocommerce\u内容有关,因为我有woocommerce.php文件根目录e、 然后,woocommerce忽略了单一产品模板…当我删除该模板,编辑单一产品和内容产品,使其具有我想要的页眉和页脚,然后根据类别更改循环。一切正常。谢谢
if ( ! function_exists( 'woocommerce_content' ) ) {
    function woocommerce_content() {
        if ( has_term( 'my-cat-slug', 'product_cat' ) ) {
            while ( have_posts() ) : the_post();
                wc_get_template_part( 'content', 'single-product-dogs' );
            endwhile;
        }
        else {
            while ( have_posts() ) : the_post();
                wc_get_template_part( 'content', 'single-product' );
            endwhile;
        }
    }
}
/** 
 * Override 'woocommerce_content' function
 */

if ( ! function_exists( 'woocommerce_content' ) ) {

/**
 * Output WooCommerce content.
 *
 * This function is only used in the optional 'woocommerce.php' template.
 * which people can add to their themes to add basic woocommerce support.
 * without hooks or modifying core templates.
 *
 */
function woocommerce_content() {

    if ( is_singular( 'product' ) ) {

        while ( have_posts() ) : the_post();

            // Template depends from category slug
        
            if ( has_term( 'my-cat-slug', 'product_cat' ) ) {

              woocommerce_get_template_part( 'content', 'single-product-dogs' );  

            } else {

              woocommerce_get_template_part( 'content', 'single-product' ); 

            }

        endwhile;

    } else { ?>

        <?php if ( apply_filters( 'woocommerce_show_page_title', true ) ) : ?>

            <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>

        <?php endif; ?>

        <?php do_action( 'woocommerce_archive_description' ); ?>

        <?php if ( have_posts() ) : ?>

            <?php do_action('woocommerce_before_shop_loop'); ?>

            <?php woocommerce_product_loop_start(); ?>

                <?php woocommerce_product_subcategories(); ?>

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

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

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

            <?php woocommerce_product_loop_end(); ?>

            <?php do_action('woocommerce_after_shop_loop'); ?>

        <?php elseif ( ! woocommerce_product_subcategories( array( 'before' => woocommerce_product_loop_start( false ), 'after' => woocommerce_product_loop_end( false ) ) ) ) : ?>

            <?php wc_get_template( 'loop/no-products-found.php' ); ?>

        <?php endif;

    }
  }
}