前提条件
Snow Monkeyの v5.0 以上
手順
1.Snow Monkeyのカスタマイズ用プラグインを用意する
プラグインの有効化や初期設定はこちら
(https://snow-monkey.2inc.org/2019/02/04/my-snow-monkey-plugin/)
2.my-snow-monkey.phpを開き下記のコードを記入してください
〜/wp-content/plugins/my-snow-monkey/my-snow-monkey.php
//my-snow-monkeyでwoocommerceのテンプレートをオーバーライド
add_filter( 'woocommerce_locate_template', 'hogehoge_woocommerce_plugin_template', 1, 3 ); //hogehoge_woocommerce_plugin_templateはユニーク
function hogehoge_woocommerce_plugin_template( $template, $template_name, $template_path ) { //hogehoge_woocommerce_plugin_templateはユニーク
global $woocommerce;
$_template = $template;
if ( ! $template_path )
$template_path = $woocommerce->template_url;
$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/template/woocommerce/';
// Loo within passed path within the theme - this is priority
$template = locate_template(
array(
$template_path . $template_name,
$template_name
)
);
if( ! $template && file_exists( $plugin_path . $template_name ) )
$template = $plugin_path . $template_name;
if ( ! $template )
$template = $_template;
return $template;
}
3. 〜/wp-content/plugins/my-snow-monkey/template/woocommerce/ 配下で
〜/wp-content/plugins/woocommerce/templates/配下のテンプレートを使えるようになりましたので、
自由でにWooCommerceテンプレートを小テーマで使う感じでオーバーライドできます。
例:送信完了メールをオーバーライドする
WooCommerceのデフォルトは 〜/wp-content/plugins/woocommerce/templates/emails/customer-completed-order.php
my-snow-monkeyプラグインでカスタマイズは 〜/wp-content/plugins/my-snow-monkey/template/woocommerce/emails/customer-completed-order.php
※通常の子テーマでオーバーライドする時は、〜/wp-content/themes/子テーマ名/woocommerce/emails/customer-completed-order.php