The Must Have for WordPress
The Must Have for WordPress
×
  • Home
December 16, 2019
WooCommerce WordPress

Load WooCommerce Templates from Plugin files

by Martin Jost
No comments
2 min Reading Time
2.28 K Views
5 Score
3 Likes
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp

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.

Last updated: December 16, 2019

Load WooCommerce Templates from Plugin files Score: 5 / 5 (3votes)
Share on Facebook Tweet on Twitter Share on Linkedin Pin on Pinterest Send via E-Mail Send via WhatsApp
Plugin
The Author
Published by
Martin Jost

View all posts by Martin Jost

Related Posts
O
WordPress Open Graph in WordPress einbetten, ohne Plugin

Das Open Graph-Protokoll ermöglicht es, dass jede Webseite als “rich object” im &#82 ...

Read More
M
CSS Minify or compress CSS in PHP

For developers of plugins or themes, it is important to provide the included CSS (stylesheets) f ...

Read More
S
WordPress Set custom WordPress post format for custom post type

If you’re working with custom post types in WordPress, you may have noticed that all post ...

Read More
Read more
C
Next Post
Customize or Modify the WordPress Post Excerpt
Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Imprint
  • Privacy Policy
© 2016-2023 - wphave - The Must Have for WordPress
Login

Lost your password?

RequiredEssential cookies enable basic functions and are necessary for the proper functioning of the website.
  • Name: Cookie Status
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user's web browser allows cookies.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookie_status
  • Duration: 1 Minute
  • Name: Cookie Consent
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user agrees to allow opt-in cookies or not.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): cookieconsent_analytics, cookieconsent_marketing, cookieconsent_status
  • Duration: 1 Year
  • Name: Like Button
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already gave a like for a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): like_btn_{POST_ID}
  • Duration: 21 Days
  • Name: Post Rating
  • Provider: Owner of this website
  • Purpose: Is necessary to check whether the user has already rate a specific post.
  • Privacy Policy: https://wphave.com/privacy-policy/
  • Cookie Name(s): rating_{POST_ID}
  • Duration: 7 Days
AnalyticsStatistics cookies collect information anonymously. This information helps us to understand how our visitors use our website.
  • Name: Google Analytics
  • Provider: Google LLC
  • Purpose: Google cookie for website analysis. Generates statistical data on how the visitor uses the website.
  • Privacy Policy: https://policies.google.com/privacy
  • Cookie Name(s): _ga, _gat, _gid
  • Duration: 2 Years