My Snow MonkeyプラグインでWooCommerceのメールテンプレートをカスタマイズ(上書きする)

WordPressテーマ Snow Monkeyのカスタマイズは、子テーマでなく、My Snow Monkeyプラグインを使う手法が推奨されている。

WooCommerceをセットアップしたときに、メールテンプレートファイルをオーバーライド(上書き)して、送信するメールをカスタマイズする。

子テーマでなく、プラグインの中に配置したテンプレートファイルで、上書きする方法はこちら。(こちらの記事が参考になった、感謝です。)

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;
}

これで、プラグインの中に配置したファイルで、上書きできる。

wp-content

plugins

my-snow-monkey

template

woocommerce

emails

customer-completed-order.php

…..

上の場合、送信完了メールのテンプレート customer-completed-order.php を上書きできる。

この記事を書いた人

大東 信仁

カンパチが好きです。

プロフィールはこちら

10月14日開催 参加者募集中
(画像をタップ→詳細へ)

ミッションナビゲート モニター
(画像をタップ→詳細へ)

広告