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- https://dev.shopvitalsleep.com/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.

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.