By adding a ../wp-content/themes/my-theme/woocommerce/ folder to a WordPress theme, WooCommerce loads your custom templates directly from your theme folder. The WooCommerce default templates are overridden without needing to overwrite templates in the WooCommerce plugin folder itself.

How can I load WooCommerce templates from the plugin?

By using the filter wc_get_template we can influence the loading of custom WooCommerce templates and define own templates in our plugin code. To do this, paste the following code snippet inside your plugin file and change the path to a folder where the custom WooCommerce templates are located.

Note: This filter is designed to prefer existing WooCommerce templates from the currently installed theme or child theme. If the theme has own custom WooCommerce templates, they are always load preferred to the plugin. If you want to prevent this, you should remove the following part from the functions code.

Load the woocommerce.php Template from Plugin

WooCommerce offers another way to customize templates. Adding a “woocommerce.php” file to ../wp-content/themes/your-theme/woocommerce.php is the easiest way to make customizations on WooCommerce templates. This template also affects all WooCommerce taxonomy pages, the shop page and the product pages. For more information, see the WooCommerce documentation.

But how we can include the template “woocommerce.php” via a plugin instead? The following code snippet is very helpful:

Similar to the first way to loading custom WooCommerce templates from the plugin, this function also searches for an existing “woocommerce.php” template in the activated theme. If this template is not available, the template of the plugin is used instead. Of course, you can change this process as you like.