If you’ve ever customized a WordPress theme, you’re probably familiar with the process of overriding templates. Overriding WooCommerce templates is a little different, but the concept is the same. In this article, we’ll show you how to override WooCommerce templates.
When you customize a WordPress theme, you can create a new template file and save it in your child theme’s directory. WordPress will automatically use your new template file instead of the default template file from the parent theme. You can override just about any template file in this way.
WooCommerce templates are different. They’re actually stored in your WooCommerce plugin directory (wp-content/plugins/woocommerce/templates/). This is done for a few reasons:
- To make sure that customizations aren’t lost when the WooCommerce plugin is updated
- To make it easier for WooCommerce developers to update the plugin
If you want to customize a WooCommerce template, you have two options:
- Copy the template file from the WooCommerce plugin directory into your child theme’s directory. This is the recommended approach since it will allow you to update the WooCommerce plugin without losing your customizations.
- Modify the template file directly in the WooCommerce plugin directory.
We do not recommend this approach. Modifying core files is generally considered bad practice since it makes updates more difficult.
Let’s say you want to customize the myaccount/form-login.php template. The first thing you need to do is copy form-login.php from (WordPress root)/wp-content/plugins/woocommerce/templates/myaccount/
. Paste it into (WordPress root)/wp-content/themes/(your child theme)/woocommerce/myaccount/
. Now you can edit (WordPress root)/wp-content/themes/(your child theme)/woocommerce/myaccount/form-login.php
.
WordPress will automatically use this new file instead of the default one from WooCommerce.