我读了很多关于overriding the default /woocommerce/ templates 并尝试实施以下内容(这是我所能找到的最好/最相关的内容,但都无济于事):
- Load WooCommerce templates from my plugin folder first
- Override WooCommerce Template File Within a Plugin
~/wp-content/my-plugin/templates/woocommerce/single-product.php
(看起来它只是不想通过插件加载)~/wp-content/my-plugin/templates/woocommerce/archive-products.php
(看起来它只是不想通过插件加载)~/wp-content/my-plugin/templates/woocommerce-pdf-invoices-packing-slips/*
(我也希望能够override other plugin extension templates 就像我可以在我的孩子主题中一样EDIT:
友好的人们SkyVerge 向我发送了以下代码,我对其进行了测试,并确认其适用于模板零件。
上述代码适用于以下情况:// Locate the template in a plugin function myplugin_woocommerce_locate_template( $template, $template_name, $template_path ) { $_template = $template; if ( ! $template_path ) { $template_path = WC()->template_path(); } $plugin_path = myplugin_plugin_path() . \'/templates/\'; // Look within passed path within the theme - this is priority $template = locate_template( array( trailingslashit( $template_path ) . $template_name, $template_name ) ); // Modification: Get the template from this plugin, if it exists if ( ! $template && file_exists( $plugin_path . $template_name ) ) { $template = $plugin_path . $template_name; } // Use default template if ( ! $template ) { $template = $_template; } return $template; } add_filter( \'woocommerce_locate_template\', \'myplugin_woocommerce_locate_template\', 10, 3 ); // Helper to get the plugin\'s path on the server function myplugin_plugin_path() { // gets the absolute path to this plugin directory return untrailingslashit( plugin_dir_path( __FILE__ ) ); }
~/myplugin/templates/single-product/product-image.php
~/myplugin/templates/single-product.php
有一些解决方案可以覆盖WC模板的各个部分,但我还没有找到/能够创建一个全面覆盖WC模板的解决方案(即覆盖能力就像子主题一样)
- 我似乎找不到过滤器挂钩的正确组合;单一产品。php和归档产品。php似乎是由标准WC模板函数之外的函数控制的,请提前感谢!