WooCommerce shop page to use my custom template

  • Before asking the question I want to tell you that I have already asked the question in https://stackoverflow.com/questions/15025213/wordpress-woocommerce-template-file-overiding

    I am using the WooCommerce plugin to develop a website. Everything is fine with WooCommerce. As per my requirement, I have configured my home page as a shop base page from the WooCommerce dashboard to make my home page the shop page. Now my requirement is to place some images which should be uploaded from the admin side and to show some text over the images. For that feature, I searched over Google and some people suggested that I use WordPress Advanced Custom Fields. I just installed it.

    Now I saw that WooCommerce is not using my custom theme. It is using its own custom theme. Since I want to show images and text using the Advanced Custom Fields plugin, I really need my own custom template to use the queries for images and text. Then I again searched over the Google for a solution and I got the suggestion to just make a copy of the theme's page.php into woocommerce.php and then just replace the code:

         <?php while ( have_posts() ) : the_post(); ?>
    
          <?php get_template_part( 'content', 'page' ); ?>
    
          <?php comments_template( '', true ); ?>
    
        <?php endwhile; // end of the loop. ?>
    

    with

    <?php woocommerce_content(); ?>
    

    I did that but still I am not getting my custom fields from Advanced Custom Fields. So kindly help me. Any suggestions and help will be appreciable. Thanks.

    My code to show the Advanced Custom Fields for image and text is like this:

    <?php $product_tab_banner = get_field('product_tab_banner');
        if($product_tab_banner): ?>
       <?php var_dump($product_tab_banner); ?>
        <div class="nt-highlighted-products">
        <img src="<?php echo $product_tab_banner['url']; ?>" alt="<?php echo $product_tab_banner['alt']; ?>"  width="<?php echo $product_tab_banner['sizes']['featured_product-width'];?>" height="<?php echo $product_tab_banner['sizes']['featured_product-height'];?>" title="<?php echo $product_tab_banner['title']; ?>" />
        </div>
      <?php endif; ?>
    

    I am using the WordPress TwentyEleven theme.

    @brasofilo I have searched over the documentation but not got any clue there...

    Check if this helps.

    yes I tried that but it is showing like this `Fatal error: Cannot redeclare show_template() (previously declared `

    There was a mistake with the function name, just corrected it.

    nope the same problem with me `Fatal error: Cannot redeclare so_9405896_show_template()`

  • user159377

    user159377 Correct answer

    8 years ago

    By going through your question I want to tell you that woocommerce will not use your custom template. It will use its own template. As you want to use wordpress advanced custom fields plugin I want to tell you is that feature only works on the page and post. So as woocommerce will not allow to use your own custom template you can't use advanced custom fields features.

    Now just do something different. Just make your own custom template where you want to show your products. Then just go to the site http://docs.woothemes.com/document/woocommerce-shortcodes/ Here you can see the shortcodes for the woocommerce. Where you can easily show almost all products with your own customization. Now use these shortcodes to show the products. Here you have achieved that woocommerce is using your own custom template. Now as it is your own template you can easily use advanced custom fields with this. Is that clear? If any thing you can't understand then reply me. Hope this will help you.

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM