/** * Override Classic Commerce template files from a plugin */ // Override Template Parts add_filter('wc_get_template_part', 'override_woocommerce_template_part', 10, 3); function override_woocommerce_template_part($template, $slug, $name) { $template_directory = plugin_dir_path( __FILE__ ) . 'templates/'; if ($name) { $path = $template_directory . "{$slug}-{$name}.php"; } else { $path = $template_directory . "{$slug}.php"; } return file_exists($path) ? $path : $template; } // Override Templates add_filter('woocommerce_locate_template', 'override_woocommerce_template', 10, 3); function override_woocommerce_template($template, $template_name, $template_path) { $template_directory = plugin_dir_path( __FILE__ ) . 'templates/'; $path = $template_directory . $template_name; return file_exists($path) ? $path : $template; }