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.






Leave a Reply