概要
woocommerce_email_heading_$THIS->ID
フィルタは、WooCommerceプラグイン内で特定の電子メール通知のヘッダーをカスタマイズするために使用されます。このフィルタは、さまざまなメールタイプに応じて、異なるヘッダーを動的に変更するために利用されます。以下に示すように、特定のフィルタによってWooCommerceのメール関連機能を個別に調整できるため、カスタマーエクスペリエンスを向上させるのに非常に役立ちます。
このフィルタは、次のような機能を実装する際によく使われます:
1. 注文確認メールのヘッダーをカスタマイズ
2. 新規登録確認メールのヘッダーを変更
3. 注文キャンセルメールのカスタムヘッダー
4. 商品発送通知メールのヘッダー改変
5. 顧客レビュー依頼メールのヘッダーの調整
6. 定期購入のリマインダーメールのカスタムヘッダー
構文
add_filter( 'woocommerce_email_heading_$THIS->ID', 'custom_email_heading', 10, 2 );
パラメータ
$heading
: 変更されるメールヘッダーのテキスト。$email_id
: メールのID(例:new_order
,customer_invoice
など)。
戻り値
カスタマイズされたメールヘッダーのテキスト。
使用可能なプラグイン・バージョン
- WooCommerceのバージョン: 4.0以降
- WordPressのバージョン: 5.0以降
サンプルコード
サンプル1: 注文確認メールのヘッダーをカスタマイズ
add_filter( 'woocommerce_email_heading_new_order', 'custom_new_order_email_heading', 10, 2 );
function custom_new_order_email_heading( $heading, $order ) {
return '新しい注文明細: ' . $order->get_order_number();
}
このサンプルコードは、新しい注文メールのヘッダーを「新しい注文明細: 注文番号」にカスタマイズします。
サンプル2: お礼メールのヘッダーを変更
add_filter( 'woocommerce_email_heading_customer_completed_order', 'custom_completed_order_email_heading', 10, 2 );
function custom_completed_order_email_heading( $heading, $order ) {
return 'ご注文が完了しました!';
}
このサンプルコードは、顧客の完了した注文のメールヘッダーを「ご注文が完了しました!」に変更します。
サンプル3: 定期購入のリマインダーメールのヘッダーを調整
add_filter( 'woocommerce_email_heading_customer_subscription_renewal', 'custom_subscription_renewal_email_heading', 10, 2 );
function custom_subscription_renewal_email_heading( $heading, $subscription ) {
return 'お支払いのリマインダー';
}
このサンプルコードは、定期購入のリマインダーメールのヘッダーを「お支払いのリマインダー」に変更します。
サンプル4: キャンセルメールのヘッダーをカスタマイズ
add_filter( 'woocommerce_email_heading_customer_cancelled_order', 'custom_cancelled_order_email_heading', 10, 2 );
function custom_cancelled_order_email_heading( $heading, $order ) {
return '注文がキャンセルされました';
}
このサンプルコードは、注文がキャンセルされた際のメールヘッダーを「注文がキャンセルされました」に変更します。
サンプル5: 商品発送通知メールのヘッダー変更
add_filter( 'woocommerce_email_heading_customer_shipped_order', 'custom_shipped_order_email_heading', 10, 2 );
function custom_shipped_order_email_heading( $heading, $order ) {
return '発送通知: あなたの注文が発送されました';
}
このサンプルコードは商品の発送通知メールのヘッダーを「発送通知: あなたの注文が発送されました」に変更します。
この関数のアクションでの使用可能性
アクション | 使用可能性 |
---|---|
mu_plugin_loaded | |
registered_post_type | |
plugins_loaded | |
wp_roles_init | |
setup_theme | |
after_setup_theme | |
set_current_user | |
init | |
register_sidebar | |
wp_loaded | |
send_headers | |
parse_query | |
pre_get_posts | |
wp | |
template_redirect | |
get_header | |
wp_head |