Hi,
I have been trying to add text and images to the top of the shop category pages.
I have worked with copies of the woocommerce template files with success before, and the file structure is correct for the template file copies (/public_html/wp-content/themes/"my theme"/woocommerce).
From what I understand, I need to edit the "archive-product.php" file. But when I try and add any text as a test, it does not show up.
For example I edited this on line 29:
<h1 class="page-title">TEST<?php woocommerce_page_title(); ?>TEST</h1>
And 'TEST' does not show up anywhere. Also, existing plugins that add banners to shop category pages do no work for me either. So that may be indicative of something.
So what do I need to do here? Am I even working with the right template file ("archive-product.php" )?
Thanks
Navjot Singh answers:
Try [[LINK href="http://stackoverflow.com/a/22972728/772709"]]this[[/LINK]] solution.
bgnh comments:
Navjot. That seems to be in the right direction. It allows the "archive-product.php" file edits to appear, but it breaks the layout of the site (makes it look like multiple overlapping content wrappers in the main area, footer gets overlapped, and sidebar drops )
Navjot Singh comments:
You will need to make sure the div and all html tags in your archive-product.php matches the original woocommerce file.
bgnh comments:
Navjot. The files match. For now I'm not even overriding the file until I can fix the layout.
Navjot Singh comments:
Another way is to just replicate the woocommerce templates folder inside your theme like you probably already did and then delete the woocommerce.php file from your theme's folder. Now you will be able to override all files. Though you would probably need to redo all the customisations done via the woocommerce.php.
This is not the recommended way though but would work.
The officially recommended way is to use the [[LINK href="http://docs.woothemes.com/document/third-party-custom-theme-compatibility/#section-2"]]hooks method[[/LINK]] and use the appropriate hook in archive-product.php and make your edits.
Francisco Javier Carazo Gil answers:
Save your original archive-product.php and then edit it and clear all this.
Then reload, if you see it blank, your override is working, if not, there is something more.
Maybe:
a) a cache in your browser, a plugin of cache or something like Cloud Fare
b) your theme structure to override WooCommerce is not correct
c) is this theme really activated?
d) if your theme is a child theme, make sure you are doing the override in the child theme and not in the parent one
Tell us.
Andrea P answers:
Hello,
do you have a file called taxonomy-product_cat.php ?
that is the file which is then normally including the archive.php in order to use that for the product taxonomy. maybe it has been edited, or missing, and so your file is not including the archive-product.php and rather is using the theme's default index.php.
when wp has to display a custom taxonomy (like product categories) it will search for a file called taxonomy-TAX-SLUG.php.
it won't look for archive-products.php, that's just a woocommerce file to make clearer which is the scope of that file, but we have to tell wordpress that for the taxonomy of product categories, it will have to use that file, otherwise if it is not finding the taxonomy template, it will fall back to index.php for displaying the product categories archives.
the file taxonomy-product_cat.php normally contains this code:
<?php
/**
* The Template for displaying products in a product category. Simply includes the archive template.
*
* Override this template by copying it to yourtheme/woocommerce/taxonomy-product_cat.php
*
* @author WooThemes
* @package WooCommerce/Templates
* @version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
woocommerce_get_template( 'archive-product.php' );
that solution on stack overflow seems to be kind of a dirty-hack. I wouldn't recommend it, and probably if you create the taxonomy-product_cat.php file, the layout won't be broken neither, as that is the standard structure that woocommerce is expecting.
p.s. if you have other product custom taxonomies in addition to the default product categories, you'd have to create other duplicates of the taxonomy-product_cat.php file, and change the tax-slug within the name. so if you have a custom taxonomy which is product-type, you'll create a file called taxonomy-product-type.php
let me know how it goes.
cheers!