The WooCommerce template files are different from the WordPress Template files look at this to see how it works and the template file for shop pages is archive-product.php
Usually, all themes provide a separate sidebar area for the shop page, did you check if your theme is compatible with WooCommerce?
If yes then you should have a sidebar available under Appearance->Widgets with name similar to 'Shop Sidebar'
How to override a template?
To override the shop page,
copy: wp-content/plugins/woocommerce/templates/archive-product.php
to wp-content/themes/your_theme_name/woocommerce/archive-product.php
and then make the necessary changes to the template in your themes folder.
What happens is WooCommerce checks for the archive-product.php file in theme directory first and if it finds a file in woocommerce/ directory then it will use that file instead of the default one.
So now you have to edit the file inside your_theme_folder/woocommerce to make any changes.
Videos
The WooCommerce template files are different from the WordPress Template files look at this to see how it works and the template file for shop pages is archive-product.php
Usually, all themes provide a separate sidebar area for the shop page, did you check if your theme is compatible with WooCommerce?
If yes then you should have a sidebar available under Appearance->Widgets with name similar to 'Shop Sidebar'
How to override a template?
To override the shop page,
copy: wp-content/plugins/woocommerce/templates/archive-product.php
to wp-content/themes/your_theme_name/woocommerce/archive-product.php
and then make the necessary changes to the template in your themes folder.
What happens is WooCommerce checks for the archive-product.php file in theme directory first and if it finds a file in woocommerce/ directory then it will use that file instead of the default one.
So now you have to edit the file inside your_theme_folder/woocommerce to make any changes.
If you are using custom WooCommerce template overrides in your theme you need to declare WooCommerce support using the add_theme_support function. WooCommerce template overrides are only enabled on themes that declare WooCommerce support. If you do not declare WooCommerce support in your theme, WooCommerce will assume the theme is not designed for WooCommerce compatibility and will use shortcode-based unsupported theme rendering to display the shop.
Declaring WooCommerce support is straightforward and involves adding one function in your theme's functions.php file.
function mytheme_add_woocommerce_support() {
add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'mytheme_add_woocommerce_support' );
Now override the template file
copy: wp-content/plugins/woocommerce/templates/archive-product.php
to wp-content/themes/your_theme_name/woocommerce/archive-product.php
I think you're a bit confused about how WooCommerce template overrides work. Here's some important info you should be aware of:
- Installing WooCommerce won't modify your theme at all.
- You shouldn't have a
woocommerce/templates/directory in your theme, even if the theme is overriding default WooCommerce templates. Rather, you may have awoocommerce/directory (without thetemplates/directory). - WooCommerce templates are overridden by copying template files from
/wp-content/plugins/woocommerce/templates/xxx.phptowp-content/themes/yourtheme/woocommerce/xxx.php
If you aren't seeing a woocommerce directory in your theme, that means that your theme is using the default WooCommerce templates. If you would like to override them, you need to copy the product-archive.php template from the WooCommerce plugin templates directory into a woocommerce/ directory within your theme.
More info in the WooCommerce documentation.
By default, there won't be any woocommerce fil s inside your theme folder. If you want to customize the Woocommerce tempalte files, you need to copy the files which you want to edit from TEMPLATES folder inside the Woocommerce plugin folder and paste inside your theme folder under folder name called WOOCOMMERCE.
WooCommerce uses the template_include filter/hook to load main templates like archive-product.php and single-product.php. And here's the class which handles main templates.
And there's a filter in that class which you can use to capture the default file (name) which WooCommerce loads based on the current request/page — e.g. single-product.php for single product pages.
You can't, however, simply hook to that filter, return a custom template path and expect it to be used (because the path has to be relative to the active theme folder). But you can do something like in the second snippet below (which is tried & tested working on WordPress 5.2.2 with WooCommerce 3.6.5, the latest version as of writing):
First, a helper function:
// Helper function to load a WooCommerce template or template part file from the // active theme or a plugin folder. function my_load_wc_template_file( $template_name ) { // Check theme folder first - e.g. wp-content/themes/my-theme/woocommerce. $file = get_stylesheet_directory() . '/woocommerce/' . $template_name; if ( @file_exists( $file ) ) { return $file; } // Now check plugin folder - e.g. wp-content/plugins/my-plugin/woocommerce. $file = 'full/path/to/your/plugin/' . 'woocommerce/' . $template_name; if ( @file_exists( $file ) ) { return $file; } }To override main WooCommerce templates (e.g.
single-product.php):add_filter( 'woocommerce_template_loader_files', function( $templates, $template_name ){ // Capture/cache the $template_name which is a file name like single-product.php wp_cache_set( 'my_wc_main_template', $template_name ); // cache the template name return $templates; }, 10, 2 ); add_filter( 'template_include', function( $template ){ if ( $template_name = wp_cache_get( 'my_wc_main_template' ) ) { wp_cache_delete( 'my_wc_main_template' ); // delete the cache if ( $file = my_load_wc_template_file( $template_name ) ) { return $file; } } return $template; }, 11 );To override WooCommerce template parts (retrieved using
wc_get_template_part()):add_filter( 'wc_get_template_part', function( $template, $slug, $name ){ $file = my_load_wc_template_file( "{$slug}-{$name}.php" ); return $file ? $file : $template; }, 10, 3 );To override other WooCommerce templates (retrieved using
wc_get_template()orwc_locate_template()):add_filter( 'woocommerce_locate_template', function( $template, $template_name ){ $file = my_load_wc_template_file( $template_name ); return $file ? $file : $template; }, 10, 2 );
Btw, there's also the woocommerce_template_path filter for those of you who're just looking to change the default WooCommerce templates folder (woocommerce) in the active theme folder.
function woo_template_replace( $located, $template_name, $args, $template_path, $default_path ) {
if( file_exists( plugin_dir_path(__FILE__) . 'templates/' . $template_name ) ) {
$located = plugin_dir_path(__FILE__) . 'templates/' . $template_name;
}
return $located;
}
function woo_get_template_part( $template , $slug , $name ) {
if( empty( $name ) ) {
if( file_exists( plugin_dir_path(__FILE__) . "/templates/{$slug}.php" ) ) {
$template = plugin_dir_path(__FILE__) . "/templates/{$slug}.php";
}
} else {
if( file_exists( plugin_dir_path(__FILE__) . "/templates/{$slug}-{$name}.php" ) ) {
$template = plugin_dir_path(__FILE__) . "/templates/{$slug}-{$name}.php";
}
return $template;
}
add_filter( 'wc_get_template' , 'woo_template_replace' , 10 , 5 );
add_filter( 'wc_get_template_part' , 'woo_get_template_part' , 10 , 3 );
You can use this snippet in your plugin root file and place your all woocommerce templates file in templates directory.
Plugin structure for reference
plugins
woo-template-replace (plugin root folder)
woo-template-replace.php (plugin root file)
templates (folder)
single-content.php (woocommerce template file)
searchform.php (woocommerce template file)