概要
woocommerce_exporter_product_types
フィルタは、WooCommerceでの商品エクスポート機能を拡張するために使用されます。このフィルタを使用することで、エクスポートされる商品のタイプを変更したり、新しい商品タイプを追加したりすることが可能です。主に以下のような機能を実装する際に利用されます。
- カスタム商品タイプを追加する
- 特定の条件に基づいてエクスポートする商品タイプをフィルタリングする
- 商品データのエクスポート機能をカスタマイズする
- エクスポートされるデータのフォーマットを変更する
- 特定の商品属性をエクスポートから除外する
- 第三者のエクスポートツールとの互換性を持たせる
構文
add_filter('woocommerce_exporter_product_types', 'your_custom_function');
パラメータ
array $types
: 現在のエクスポート対象商品タイプの配列。
戻り値
array
: フィルタリングされた商品タイプの配列。
使用可能なバージョン
- WooCommerce: 3.0.0以上
- WordPress: 4.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_exporter_product_types', function($types) {
$types[] = 'custom_product_type';
return $types;
});
このコードは、カスタム商品タイプcustom_product_type
をエクスポート対象の商品タイプのリストに追加します。
引用元: https://docs.woocommerce.com/
サンプルコード 2
add_filter('woocommerce_exporter_product_types', function($types) {
return array_diff($types, ['external']);
});
このコードは、デフォルトのエクスポート商品タイプからexternal
タイプを除外します。
引用元: https://github.com/woocommerce/woocommerce
サンプルコード 3
add_filter('woocommerce_exporter_product_types', function($types) {
return ['simple', 'variable', 'virtual'];
});
このコードでは、エクスポート対象の商品タイプをsimple
、variable
、virtual
の3つに制限します。
引用元: https://example.com/woocommerce-guide
サンプルコード 4
add_filter('woocommerce_exporter_product_types', function($types) {
if (is_user_logged_in() && current_user_can('manage_options')) {
$types[] = 'downloadable';
}
return $types;
});
このコードは、ログインしているユーザーが管理者権限を持つ場合にのみ、downloadable
商品タイプをエクスポート対象に追加します。
引用元: https://developer.wordpress.org/
サンプルコード 5
add_filter('woocommerce_exporter_product_types', function($types) {
return array_merge($types, ['subscription']);
});
このコードでは、subscription
商品タイプをエクスポート対象の商品タイプに追加します。
引用元: https://woocommerce.com/