20

I'm trying to customize the standard woocommerce theme and so far that has worked well. I copied all template files from /plugins/woocommerce/templates to /mytheme/woocommerce and customized the files.

But when i'm change something in archive-product.php nothing happens? I even tried to customize this in the core files (/plugins/woocommerce/templates/archive-product.php) but i doesn't work.

I want to change the class of the h1 heading: <h1 class="page-title"><?php woocommerce_page_title(); ?></h1>.

So i looked up all woocommerce template files, the class page-title occurs only in this one file (to prevent editing the wrong file).

Edit:

In detail, i want to customize the theme used in this path: http://example.com/product-category/mycategory

Slevin
  • 4,268
  • 12
  • 40
  • 90

7 Answers7

60

I tried all the above solutions, to no avail. No matter what I did, the archive-product.php was not being used at all. Instead, most woocommerce pages were using page.php from my theme.

The solution for me was to add theme support... Which, it's been a while since I used woocommerce, so I completely forgot about that. But after adding the following line to my functions.php file, archive-product.php is now being used (/mytheme/woocommerce/archive-product.php) and I can update it, as I should be able to.

add_theme_support('woocommerce');
IAteYourKitten
  • 968
  • 1
  • 6
  • 13
  • 1
    thanks for that insight. in my case i had issues with a filter being applied, not even a template overwrite. it was not working until i added the wc theme support. strange.. – honk31 May 15 '18 at 13:39
  • 1
    Works fine! Thank you. – moreirapontocom Jul 05 '18 at 23:55
  • 1
    Not sure how I missed this, but thanks for the reminder! – dungey_140 Jan 29 '19 at 09:52
  • 1
    Omg! I completely forgot about this! =PPP I was having troubles and now all strucuture is fixed! The woocommerce folder inside my theme is working great now and also the body class are back. Example: pressing ctrl+u to display the source code I can see now all the page types added to body class! Thanks so much! – Tiago Apr 01 '19 at 16:22
  • 1
    If you add the theme support, then WooCommerce decides to always show a sidebar in your theme even if you don't have any. If you don't add theme support, there's no way to remove the category description hook. Great piece of software. – Marc Oct 11 '19 at 06:19
  • @Slevin This should be an accepted answer for anybody else who comes accross this issue :) Thanks – Alex Chebotarsky Sep 21 '20 at 10:02
  • if your theme is already setup then add this code with ```after_setup_theme```. Works for me ```function mytheme_add_woocommerce_support() { add_theme_support( 'woocommerce' ); } add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' ); ```. – Bhagchandani Nov 29 '20 at 12:35
  • This is the real answer. – David T Feb 09 '21 at 18:27
25

Seems this is STILL an issue in Woocommerce. For anyone landing here, the following solution was working for me as of version 2.1.6.

Apparently the problem is due to the function woocommerce_content() outputting the wrong page for archive content.

I used the following to get around it:

replace woocommerce_content() in woocommerce.php with:

if ( is_singular( 'product' ) ) {
 woocommerce_content();
}else{
//For ANY product archive.
//Product taxonomy, product search or /shop landing
 woocommerce_get_template( 'archive-product.php' );
}

Credit: found the solution here

Talk nerdy to me
  • 1,085
  • 9
  • 11
9

Here's how I fixed mine:

  1. Delete woocommerce.php in your theme folder.
  2. Copy TEMPLATE folder in woocommerce plugin dir, paste it in your THEME folder, and rename it to woocommerce.
  3. Open the folder you just renamed, go to shop folder, and edit wrapper-start.php and wrapper-end.php.
Van Leo Adrivan
  • 109
  • 1
  • 5
  • 1
    Wow... this worked, but goes against everything according to the WooCommerce documentation for adding compatibility to a theme. Is this a bug? This seems like a scary work around but definitely works. – RCNeil Dec 07 '13 at 23:53
4

If you use the woocommerce.php method you cannot customize archive-product. You must use the hooks method

http://docs.woothemes.com/document/third-party-custom-theme-compatibility/ Please note: when creating woocommerce.php in your theme’s folder, you won’t be able to override the woocommerce/archive-product.php custom template as woocommerce.php has the priority over archive-product.php. This is intended to prevent display issues.

2

you need to edit the file "taxonomy-product_cat.php" and add a conditional is_product_category( 'mycategory' ).

  1. open your theme folder and add a new subfolder named "woocommerce" to it.
  2. copy the files "archive-product.php" and "taxonomy-product_cat.php" from /plugins/woocommerce/templates to the woocommerce subfolder in your theme.
  3. rename "archive-product.php" to "archive-mycategory.php" (or whatever you like, this will be the template file to the category).
  4. open "taxonomy-product_cat.php" and wrap the wc_get_template( 'archive-product.php' ); with:
    if (is_product_category( 'mycategory' )){
        wc_get_template( 'archive-mycategory.php' );
    }  else {
        wc_get_template( 'archive-product.php' );
    }
MaxiGui
  • 6,190
  • 4
  • 16
  • 33
2

For others searching here, doublecheck the path. It is for example not /mytheme/woocommerce/templates/archive-product.php but only /mytheme/woocommerce/archive-product.php. I didn't have to apply @Talk nerdy to me's patch or any other to make it work.

Fanky
  • 1,673
  • 1
  • 18
  • 20
0

I'm developing a custom Wordpress theme with Woocommerce and Elementor and I encountered the same error. I copied the archive-product.php from the original woocommerce directory and placed in into /mytheme/woocommerce/ directory. I then created a new product archive template through the Elementor template builder. I then added added this piece of code to functions.php:

function woocommerce_custom_archive_template( $template ) {
  if ( is_post_type_archive( 'product' ) ) {
    $new_template = locate_template( array( 'archive-product.php' ) );
    if ( '' != $new_template ) {
      return $new_template ;
    }
  }
  return $template;
}

This function is used to customize the WooCommerce product post type archive page template. It checks if the archive is for the product post type, and if it is, it looks for a custom archive-product.php template file in the theme folder. If the file exists, it loads the custom template instead of the default WooCommerce template. This function is necessary if you want to customize the product archive page template in your theme.

In combination with add_theme_support('woocommerce'); this solved my issue. Hope it will help other developers in the future!

TawabG
  • 509
  • 5
  • 8