admin管理员组

文章数量:1277887

I´m making my first Woocommerce theme. In the documentation and in plugins/woocommerce/templates/single-product.php, it´s written :

This template can be overridden by copying it to yourtheme/woocommerce/single-product.php

But when I do this, it does not work and if I put the file on my theme root, it got it, why ?

Comments inside files and WooCommerce documentation are not updated ?

I´m making my first Woocommerce theme. In the documentation and in plugins/woocommerce/templates/single-product.php, it´s written :

This template can be overridden by copying it to yourtheme/woocommerce/single-product.php

But when I do this, it does not work and if I put the file on my theme root, it got it, why ?

Comments inside files and WooCommerce documentation are not updated ?

Share Improve this question asked Oct 23, 2019 at 16:56 J.BizMaiJ.BizMai 9002 gold badges10 silver badges30 bronze badges 3
  • 2 did you add add_theme_support( 'woocommerce' ); in your theme ? – Chetan Vaghela Commented Oct 23, 2019 at 17:45
  • 2 @Chetan is correct. And single-product.php in the root theme folder works because that is a valid/recognized template for single posts of the product type - i.e. single-<post type>.php - and by default, it has a higher priority and would be used even if your theme does have woocommerce/single-product.php. – Sally CJ Commented Oct 23, 2019 at 18:37
  • @ChetanVaghela Thank you ! It´s exaclty what I wanted to know. – J.BizMai Commented Oct 23, 2019 at 19:24
Add a comment  | 

2 Answers 2

Reset to default 1

As @ChetanVaghela said in comments, to use the woocommerce structure you need to add this code line :

add_theme_support( 'woocommerce' ); 

Sally in the comments above gave a very informative answer to this question, which answers the OP.

I would like to quote it again:

single-product.php in the root theme folder works because that is a valid/recognized template for single posts of the product type - i.e. single-<post type>.php - and by default, it has a higher priority and would be used even if your theme does have woocommerce/single-product.php

Also Chetan mentioned to add theme support with

add_theme_support( 'woocommerce' ); 

But note, if at woocommerce.php file resides a your your theme's root folder, the single-product.php and archive-product.php wont work.

WooCommerce plugin comes with a handy checking tool at your Dashboard. Go the WooCommerce -> Status

  • And it reports if your theme has been modified to add wocommerce support or not.
  • Any flags to notice
  • And at the last section it shows the list of template files which are overwritten and if there are issues regarding them. For example, if your theme has a woocommerce.php it would notify you it too!

本文标签: theme developmentwhy mythemesingleproductphp works but not mythemewoocommercesingleproductphp