您可以使用wc_get_template
过滤器,允许您在模板包含之前覆盖模板的绝对文件路径。例如,此覆盖checkout/payment.php
:
add_filter( \'wc_get_template\', function ( $file, $name ) {
if ( $name === \'checkout/payment.php\' ) {
// $file must be an absolute filepath
// e.g. path relative to current file
$file = __dir__ . \'/templates/checkout/payment.php\';
// e.g. path relative to parent directory
$file = dirname( __dir__ ) . \'/templates/checkout/payment.php\';
}
return $file;
}, 10, 2 );