概要
woocommerce_email_recipient_backorder
フィルタは、WooCommerceがバックオーダー商品の通知メールを送信する際に、その受信者のメールアドレスをカスタマイズするために使用されます。このフィルタは、必要に応じて特定のアドレスを追加または削除するコンテキストを提供します。主に以下の機能を実装する際に活用されます。
- バックオーダー通知の受信者をカスタマイズする
- 特定のロールのユーザーにのみ通知を送る
- メールアドレスのバリデーションを追加する
- チームメンバー専用の通知アドレスを設定する
- 外部サービスへ情報を連携するためにメールアドレスを設定する
- 通知受信者を条件に応じて変更する
構文
add_filter( 'woocommerce_email_recipient_backorder', 'custom_backorder_email_recipient', 10, 2 );
パラメータ
$recipient
(string) – 元の受信者のメールアドレス$order
(WC_Order) – 対象の注文オブジェクト
戻り値
- (string)変更後の受信者のメールアドレス
使用可能なプラグインおよびバージョン
- WooCommerceバージョン:5.0以上
- WordPressバージョン:5.0以上
この関数のアクションでの使用可能性
アクション | 使用可能性 |
---|---|
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 |
サンプルコード
サンプルコード1
add_filter( 'woocommerce_email_recipient_backorder', 'custom_backorder_email_recipient', 10, 2 );
function custom_backorder_email_recipient( $recipient, $order ) {
// 管理者のメールアドレスを追加
$recipient .= ', admin@example.com';
return $recipient;
}
このコードは、バックオーダー通知の受信者として、元の受信者に加えて管理者のメールアドレスを追加します。
サンプルコード2
add_filter( 'woocommerce_email_recipient_backorder', 'conditional_backorder_email_recipient', 10, 2 );
function conditional_backorder_email_recipient( $recipient, $order ) {
// 現在のユーザーのロールが「shop_manager」の場合
if ( current_user_can( 'shop_manager' ) ) {
$recipient = 'shop_manager@example.com';
}
return $recipient;
}
このコードは、現在のユーザーが「shop_manager」ロールを持つ場合、受信者を特定のアドレスに変更します。
サンプルコード3
add_filter( 'woocommerce_email_recipient_backorder', 'remove_backorder_email_recipient', 10, 2 );
function remove_backorder_email_recipient( $recipient, $order ) {
// 特定のメールアドレスを削除
$recipient = str_replace( 'unwanted@example.com', '', $recipient );
return $recipient;
}
このコードは、バックオーダー通知の受信者から特定の不要なメールアドレスを削除します。
サンプルコード4
add_filter( 'woocommerce_email_recipient_backorder', 'external_service_backorder_recipient', 10, 2 );
function external_service_backorder_recipient( $recipient, $order ) {
// 外部サービス向けのメールアドレスを追加
$recipient .= ', service@example.com';
return $recipient;
}
このコードは、バックオーダー通知の受信者に外部サービス向けのメールアドレスを追加します。
サンプルコード5
add_filter( 'woocommerce_email_recipient_backorder', 'modify_recepient_based_on_order_status', 10, 2 );
function modify_recepient_based_on_order_status( $recipient, $order ) {
// 注文のステータスが「processing」の場合、特定の受信者を追加
if ( $order->get_status() == 'processing' ) {
$recipient .= ', processing@example.com';
}
return $recipient;
}
このコードは、バックオーダーの注文ステータスが「processing」の場合に、特定の受信者を追加します。