Wrap a WooCommerce template with your own code

Sometimes you may want to wrap a standard WooCommerce template with your own code while maintaining the original template.

For example, to wrap the template for a single product, simply create the template in your theme like you normally would when overriding it:

/wp-content/themes/mytheme/woocommerce/content-product.php

But instead of copying the content from the core WooCommerce template, simply add the following code:

//Code to run before template

load_template(WC()->plugin_path() . "/templates/content-product.php", false);

//Code to run after template

Leave a Reply

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

Markdown is allowed in comments.