概要
woocommerce_integrations
フィルタは、WooCommerceの統合機能を拡張または変更する際に使用されるフックです。このフィルタを使用することで、カスタム統合を作成したり、既存の統合に新しい機能を追加したりすることができます。
一般的に、以下のような機能を実装する際によく使われます:
- 支払いゲートウェイの追加
- 物流サービスとの統合
- 顧客データ管理システムの統合
- マーケティングオートメーションツールとの連携
- サブスクリプションサービスの統合
- 分析ツールとのデータ共有
構文
add_filter('woocommerce_integrations', 'your_custom_function');
パラメータ
$methods
: 現在の統合メソッドの配列。
戻り値
- 変更された統合メソッドの配列。
使用可能なプラグインバージョン
- WooCommerce: 2.0以降
- WordPress: 4.0以降
サンプルコード
サンプルコード 1: カスタム支払いゲートウェイの追加
このサンプルでは、新しい支払いゲートウェイをWooCommerceに追加する方法を示します。
add_filter('woocommerce_integrations', 'add_custom_gateway');
function add_custom_gateway($methods) {
$methods[] = 'WC_Custom_Gateway';
return $methods;
}
このコードは、WC_Custom_Gateway
クラスを新しい支払いゲートウェイとしてWooCommerceに追加します。
引用元: https://woocommerce.com/document/payment-gateway-classes/
サンプルコード 2: 独自の出荷統合の追加
こちらのサンプルは独自の出荷統合を追加する例です。
add_filter('woocommerce_integrations', 'add_shipping_integration');
function add_shipping_integration($methods) {
$methods[] = 'WC_Shipping_Custom_Method';
return $methods;
}
このコードは、カスタム配送メソッドを追加するためのものです。
引用元: https://woocommerce.com/document/declaring-your-own-shipping-method/
サンプルコード 3: マーケティングツールとの連携
このサンプルではマーケティングツールの統合を実装します。
add_filter('woocommerce_integrations', 'add_marketing_integration');
function add_marketing_integration($methods) {
$methods[] = 'WC_Marketing_Custom_Integration';
return $methods;
}
このコードにより、カスタムマーケティング統合を追加できます。
引用元: https://woocommerce.com/document/woocommerce-api/
サンプルコード 4: 顧客データの統合
顧客データ管理システムとの統合する方法を示したサンプルです。
add_filter('woocommerce_integrations', 'add_customer_data_integration');
function add_customer_data_integration($methods) {
$methods[] = 'WC_Customer_Data_Integration';
return $methods;
}
このスニペットでは、顧客データをインポート・エクスポートする統合を追加します。
引用元: https://woocommerce.com/document/woocommerce-rest-api/
サンプルコード 5: 分析ツールの統合
ここでは分析ツールとの統合例を見てみましょう。
add_filter('woocommerce_integrations', 'add_analysis_integration');
function add_analysis_integration($methods) {
$methods[] = 'WC_Analysis_Custom_Integration';
return $methods;
}
このコードは、ウェブサイトのトラフィックや販売データ等を分析するための統合を追加します。
引用元: https://woocommerce.com/document/advanced-reports/
この関数のアクションでの使用可能性
アクション | 使用例 |
---|---|
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 |