用插件替换模板



替换cart.php模板的指令是在主题目录中创建一个副本,如

/wp-content/themes/yourtheme/woocommerce/cart/cart.php.

但我的问题是,我可以让它在一个插件,而不是一个主题,如:

/wp-content/plugins/yourplugin/woocommerce/cart/cart.php

这能行吗?如果是,这是一个很好的做法还是不推荐?

当然可以。WooCommerce为此提供了一个过滤器:

// Allow 3rd party plugin filter template file from their plugin.
$filter_template = apply_filters( 'wc_get_template', $template, $template_name, $args, $template_path, $default_path );

最新更新