×
Black Friday Savings
00Days
:
06Hours
:
46Minutes
:
45Seconds
Use Coupon 40%OFF

Includes 1 Year Priority Support

Shop Now

WP SITES

3093 Coded Tutorials & 296 Plugins

How To Load WooCommerce Templates From a Plugin

Add this PHP code to your plugin file to load WooCommerce templates from your plugin or code snippets plugin. Use wc_locate_template which has replaced woocommerce_locate_template.

add_filter( 'wc_locate_template', 'wpsites_woocommerce_template_override', 10, 3 );
function wpsites_woocommerce_template_override( $template, $template_name, $template_path ) {

    $plugin_path = plugin_dir_path( __FILE__ ) . 'woocommerce/';

    if ( file_exists( $plugin_path . $template_name ) ) {
        $template = $plugin_path . $template_name;
    }

    return $template;
}

Any template you find inside the WooCommerce templates folder can be added to a folder in your plugin named woocommerce and modified without being overridden when WooCommerce updates.

This code looks inside your plugins woocommerce folder and loads the files inside that folder.

Was this helpful?

Yes
No
Thanks for your feedback!

Leave a Reply