WooCommerce REST API v2 - 显示受保护的元数据
WooCommerce REST API v2 - Show Protected Meta Data
我正在将 WooCommerce 网站集成到我构建的应用程序中。
我正在尝试使用 API.
检索产品(元数据)的自定义字段
以下是有关从 v1 到 v2 的更改的文档的摘录
v1 does not include order item meta, v2 includes full order item meta (with an optional filter parameter to include protected order item meta)
https://woocommerce.github.io/woocommerce-rest-api-docs/v2.html#version
我似乎无法在任何地方找到这个实际的过滤器。下面的过滤器是最初用来获取元数据的过滤器
filter[meta]=true
但是通过我的搜索,我找不到 return 保护产品元数据的附加过滤器。请注意,我不是要更新受保护的元数据,而只是查看受保护的元数据。
我现在找到了解决方法。我没有在 API 调用中找到受保护字段的过滤器,但是我将以下代码添加到我的 functions.php 文件
add_filter( 'is_protected_meta', function ( $protected, $key, $type ) {
if ( $key === '_my_protected_meta_field' ) {
// Expose the `_my_protected_meta_field` meta value publicly
return false;
}
return $protected;
}, 10, 3 );
_my_protected_meta_field
的元数据现在显示在 API 与 filter[meta]=true
的调用中
我正在将 WooCommerce 网站集成到我构建的应用程序中。
我正在尝试使用 API.
检索产品(元数据)的自定义字段以下是有关从 v1 到 v2 的更改的文档的摘录
v1 does not include order item meta, v2 includes full order item meta (with an optional filter parameter to include protected order item meta)
https://woocommerce.github.io/woocommerce-rest-api-docs/v2.html#version
我似乎无法在任何地方找到这个实际的过滤器。下面的过滤器是最初用来获取元数据的过滤器
filter[meta]=true
但是通过我的搜索,我找不到 return 保护产品元数据的附加过滤器。请注意,我不是要更新受保护的元数据,而只是查看受保护的元数据。
我现在找到了解决方法。我没有在 API 调用中找到受保护字段的过滤器,但是我将以下代码添加到我的 functions.php 文件
add_filter( 'is_protected_meta', function ( $protected, $key, $type ) {
if ( $key === '_my_protected_meta_field' ) {
// Expose the `_my_protected_meta_field` meta value publicly
return false;
}
return $protected;
}, 10, 3 );
_my_protected_meta_field
的元数据现在显示在 API 与 filter[meta]=true