最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

In woocommerce product details not showing

programmeradmin1浏览0评论

I'm new in wordpress and woocommerce development part. I'm trying to integrate woocommerce for my products, everything was fine. But when i click on product permalink for product details or product single page it's redirect to the same page. Interesting thing is when i click on product, the url changed but not go through to the details page.

Here is the page link- /

I'm using loop inside woocommerce.php with my custom designed page.

Here is the code sample-

<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>

Folder structure: ../themes/theme-name/woocommerce.php

Please help me to findout where i make mistakes.

I'm new in wordpress and woocommerce development part. I'm trying to integrate woocommerce for my products, everything was fine. But when i click on product permalink for product details or product single page it's redirect to the same page. Interesting thing is when i click on product, the url changed but not go through to the details page.

Here is the page link- https://dev.shopvitalsleep/collections/all/

I'm using loop inside woocommerce.php with my custom designed page.

Here is the code sample-

<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>

Folder structure: ../themes/theme-name/woocommerce.php

Please help me to findout where i make mistakes.

Share Improve this question edited Oct 31, 2020 at 12:46 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Oct 31, 2020 at 7:16 Shamsul HudaShamsul Huda 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

I figured it out! The problem is woocommerce.php file. This file overwrite the other directory. In my case, I'm developing a custom theme that's why I need to create a directory inside my ../themes/my-theme nameed- /woocommerce/archive-product.php and delete the previous one woocommerce.php form ../themes/my-theme

So, moral of the topic is- If your theme has a woocommerce.php file, you will be unable to override the woocommerce/archive-product.php custom template in your theme, as woocommerce.php has priority over other template files. This is intended to prevent display issues.

发布评论

评论列表(0)

  1. 暂无评论