在woocommerce中未显示产品详细信息

时间:2020-10-31 05:55:34

标签: php wordpress woocommerce

我是wordpress和woocommerce开发部分的新手。我正在尝试将woocommerce集成到我的产品中,一切都很好。但是,当我单击产品永久链接以获取产品详细信息或产品单页时,它会重定向到同一页面。有趣的是,当我单击产品时,URL更改了,但没有进入详细信息页面。

这是页面链接-https://dev.shopvitalsleep.com/collections/all/

我正在使用自定义设计的页面在woocommerce.php中使用循环。

这是代码示例-

<div class="row justify-content-center equal-box">
    <?php
        $args = array(
            'post_type' => 'product',
            'posts_per_page' => 12
            );
            $loop = new WP_Query( $args );
            if ( $loop->have_posts() ) {
                while ( $loop->have_posts() ) : $loop->the_post(); 
                    $product = wc_get_product($loop->post->ID);

                    ?>
                    <div class="col-lg-6 mb-4">
                        <div class="product-content text-center">
                            <div class="product-images">
                                <a href="<?php the_permalink(); ?>" class="product-details-link">
                                <?php the_post_thumbnail('full'); ?>
                                </a>
                            </div>
                            <div class="product-info">
                              <h4 class="product-title"><?php echo get_the_title(); ?></h4>                     
                              <div class="price">
                                            
                              <p>
                                <span class="reg-price">
                                    <del>$<?php echo get_post_meta( get_the_ID(), '_regular_price', true ); ?></del>
                                </span>
                                <span class="sell-price">now $<?php echo get_post_meta( get_the_ID(), '_sale_price', true ); ?> USD</span>
                              </p>                              
                            </div>
                            </div>
                            </div>
                        <div class="row mt-auto product-content text-center mb-2">
                            <div class="col-6">
                                <a class="button style-blue view-detail-button" href="<?php the_permalink(); ?>">View Details</a>
                            </div>
                            <div class="col-6">
                                <div class="add-to-cart "><?php
                                        echo sprintf( '<a href="%s" data-quantity="1" class="%s" %s>%s</a>',
                                            esc_url( $product->add_to_cart_url() ),
                                            esc_attr( implode( ' ', array_filter( array(
                                                'button', 'product_type_' . $product->get_type(),
                                                $product->is_purchasable() && $product->is_in_stock() ? 'add_to_cart_button' : '',
                                                $product->supports( 'ajax_add_to_cart' ) ? 'ajax_add_to_cart' : '',
                                            ) ) ) ),
                                            wc_implode_html_attributes( array(
                                                'data-product_id'  => $product->get_id(),
                                                'data-product_sku' => $product->get_sku(),
                                                'aria-label'       => $product->add_to_cart_description(),
                                                'rel'              => 'nofollow',
                                            ) ),
                                            esc_html( $product->add_to_cart_text() )
                                        );
                                      ?>
                               </div>

                            </div>
                        </div>
                    </div>
                    <?php                           
                        endwhile;
                    } else {
                        echo __( 'No products found' );
                    }
                    wp_reset_postdata();
                ?>
            </div>

文件夹结构: ../themes/theme-name/woocommerce.php

请帮助我找出我犯错的地方。

2 个答案:

答案 0 :(得分:2)

您的WooCommerce单页似乎无法正常运行。
看看他们的官方文档以获取正确的文件结构。我认为您在引用错误的文件时遇到问题,或者您的woocommerce.php等核心文件已被覆盖。

您应该使用子主题,然后在此处进行编辑。

WooCommerce Docs Template Structure

答案 1 :(得分:0)

我知道了! 问题是woocommerce.php文件。该文件将覆盖另一个目录。 就我而言,我正在开发一个自定义主题,这就是为什么我需要在我的../themes/my-theme中创建一个名为/woocommerce/archive-product.php的目录并删除woocommerce.php形式../themes/my-theme

的原因

因此,该主题的寓意是- 如果您的主题具有woocommerce.php文件,则您将无法覆盖主题中的woocommerce/archive-product.php自定义模板,因为woocommerce.php的优先级高于其他模板文件。这是为了防止显示问题。