Website Building » WooCommerce » How Do I Override WooCommerce Template Files in Custom Plugin?

How Do I Override WooCommerce Template Files in Custom Plugin?

Last updated on January 13, 2023 @ 12:41 pm

If you’re a developer, then you know that overriding WooCommerce template files can be a pain. In this article, we’re going to show you how to do it in a custom plugin.

First, you’ll need to create a new plugin. You can do this by creating a new folder in your wp-content/plugins directory and adding a file called my-plugin.php to it.

Next, you’ll need to add some code to your my-plugin.php file. Here’s what you’ll need:

<php
/*
Plugin Name: My Plugin
Plugin URI: http://example.com/my-plugin
Description: A plugin to override WooCommerce template files.
Version: 1.0
Author: John Doe
Author URI: http://example.com
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) { exit; }

In the code above, we’ve created a new plugin that will override the default WooCommerce template file for completed orders. We’ve also added some code to replace the default content of the template with our own custom content. Finally, we’ve added an action hook that will instantiate our email class and add it to WooCommerce’s list of emails.

Now that our plugin is setup, we can test it out by completing an order on our WooCommerce site. Once the order is complete, we should see our custom content in the order confirmation email instead of the default content.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.