在email-order-items.php中从Woocomece访问产品元数据
在客户下订单后,我很难过滤一些发送到电子邮件中的数据。问题是,每个行项目都显示了装运信息(提货位置),即使它与订单末尾的最终提货位置相同 我已经能够查看给定的item_元数据,但我不确定如何过滤它,从根本上删除包含“Pickup Location”元键的数组部分,然后仍然打印其余部分。下面是email-order-items.php文件中生成数据的区域(这不是海关……这是商业标准): 结果: 饼干→ Cookie(一次性)数组([\u数量==>数组([0]=>1) [\u tax\u class]=>数组([0]=>)[\u产品id]=>数组([0]=>5807 )[\u变体\u id]=>数组([0]=>0)[\u行\u小计]=>数组( [0]=>2.5][\u行\总计]=>Array([0]=>0][\u行\小计\税] =>数组([0]=>0.15)[[行税]=>数组([0]=>0)[[行税数据]=>数组([0]=> a:2:{s:5:“总计”;a:1:{i:1;s:1:“0”;}s:8:“小计”;a:1:{i:1;s:4:“0.15”;} )[\u shipping\u item\u id]=>数组([0]=>28795)[取货位置]=> 数组([0]=>此处的收件地址、城市、州、邮政编码)) WC_产品_简单对象([id]=>5807[post]=>WP_post对象( [ID]=>5807[发帖作者]=>596[发帖日期]=>2016-07-23 17:55:10 [发布日期格林尼治标准时间]=>2016-07-23 21:55:10[发布内容]=>[发布标题] =>Power Protein Cookie(一次)[post_摘录]=>[post_状态]=>发布[评论状态]=>关闭[ping_状态]=>关闭 [post_密码]=>[post_名称]=>一次性能量蛋白饼干 [发送至ping]=>[pinged]=>[post\u modified]=>2016-07-23 19:39:18 [post\u modified\u gmt]=>2016-07-23 23:39:18[post\u内容过滤]=> [post\u parent]=>5806[菜单顺序]=>1[post\u类型]=>product [post\u mime\u type]=>[comment\u count]=>0[filter]=>raw) [产品类型]=>简单[装运类别:受保护]=> [装运类别\u id:受保护]=>0] 我如何遍历item_元数据,取消设置(我认为是这样做的)取货位置数据,然后仍然显示其余的数据 更新:我进入并尝试了以下代码:在email-order-items.php中从Woocomece访问产品元数据,php,wordpress,cookies,woocommerce,metadata,Php,Wordpress,Cookies,Woocommerce,Metadata,在客户下订单后,我很难过滤一些发送到电子邮件中的数据。问题是,每个行项目都显示了装运信息(提货位置),即使它与订单末尾的最终提货位置相同 我已经能够查看给定的item_元数据,但我不确定如何过滤它,从根本上删除包含“Pickup Location”元键的数组部分,然后仍然打印其余部分。下面是email-order-items.php文件中生成数据的区域(这不是海关……这是商业标准): 结果: 饼干→ Cookie(一次性)数组([\u数量==>数组([0]=>1) [\u tax\u clas
if(is_array($item_meta->meta))
{
foreach($item_meta->meta as $key => $value)
{
echo $key . '<br />' . $value;
}
}
if(是数组($item\u meta->meta))
{
foreach($item\u meta->metaas$key=>$value)
{
回显$key.
.$value;
}
}
这给了我以下几点:
饼干→ 饼干(一次)\数量
数组\u tax\u类
数组\产品\标识
数组\u变量\u id
数组\行\小计
数组\行\总计
数组\行\小计\税
数组\行\税
数组\行\税\数据
数组\u装运\u项目\u id
阵列备份位置
排列
我觉得我很接近,但不太了解item_meta内部的结构……希望您能提供帮助。@update 3-操作php
对象(未经测试):
这是我最后一次尝试:
// Cloning the base object:
$custom_meta = clone $item_meta;
// OR
// $custom_meta = new stdClass();
// $custom_meta = $item_meta;
// saving the custom array in a temporary variable
$length = sizeof($custom_meta->meta) - 1;
$meta_temp = array_slice( $custom_meta->meta, 0, $length );
// Removing the property (array) from the object
unset($custom_meta->meta);
// Recreating the same property and setting the changed array Key/Values to it
$custom_meta->meta = $meta_temp;
// Displaying your custom object (for test)
echo print_r($custom_meta);
// Using it
$custom_meta->display();
基于此线程:
@update 2-备选方案: 1) 改为使用
unset()
函数使用数组\u pop()
函数(因为我们必须删除数组中的最后一项):
2) 使用unset()
函数而不是使用数组\u slice()
函数(因为我们必须删除数组中的最后一项):
但您不会使用$item\u meta->meta
,因为$item\u meta
是一个对象,无法直接从$item\u meta->meta中删除数据
@Update(与作者评论相关)
删除数组中的键/值
,其中键
是拾取位置
首先,我们检查它是否是要删除的右侧键/值
echo $item_meta->meta['Pickup Location'] // should display right "Pickup Location" value.
一旦获得正确的值,就可以使用unset()
php函数。但首先,我们要将数组
(键
/值
)传递给新数组。这是一个过程:
// Copying the data to a new array.
$item_meta_meta_arr = $item_meta->meta;
unset($item_meta_meta_arr['Pickup Location']);
// Checking that it has correctly be unset from the array:
foreach($item_meta_meta_arr as $key => $value)
{
echo 'Key: '. $key . ' / Value: ' . $value . '<br />';
}
@update3-操作php对象(未测试):
这是我最后一次尝试:
// Cloning the base object:
$custom_meta = clone $item_meta;
// OR
// $custom_meta = new stdClass();
// $custom_meta = $item_meta;
// saving the custom array in a temporary variable
$length = sizeof($custom_meta->meta) - 1;
$meta_temp = array_slice( $custom_meta->meta, 0, $length );
// Removing the property (array) from the object
unset($custom_meta->meta);
// Recreating the same property and setting the changed array Key/Values to it
$custom_meta->meta = $meta_temp;
// Displaying your custom object (for test)
echo print_r($custom_meta);
// Using it
$custom_meta->display();
基于此线程:
@update 2-备选方案:
1) 改为使用unset()
函数使用数组\u pop()
函数(因为我们必须删除数组中的最后一项):
2) 使用unset()
函数而不是使用数组\u slice()
函数(因为我们必须删除数组中的最后一项):
但您不会使用$item\u meta->meta
,因为$item\u meta
是一个对象,无法直接从$item\u meta->meta中删除数据
@Update(与作者评论相关)
删除数组中的键/值
,其中键
是拾取位置
首先,我们检查它是否是要删除的右侧键/值
echo $item_meta->meta['Pickup Location'] // should display right "Pickup Location" value.
一旦获得正确的值,就可以使用unset()
php函数。但首先,我们要将数组
(键
/值
)传递给新数组。这是一个过程:
// Copying the data to a new array.
$item_meta_meta_arr = $item_meta->meta;
unset($item_meta_meta_arr['Pickup Location']);
// Checking that it has correctly be unset from the array:
foreach($item_meta_meta_arr as $key => $value)
{
echo 'Key: '. $key . ' / Value: ' . $value . '<br />';
}
我使用了您的第一个代码块(有一些更改…一些小错误)。我能够分离出我想要消除的代码块…它被困在这里:if(is_string($value2))echo$key2.$value2.'(级别2)
;现在的问题是,我实际上如何适当地将其从item_元容器中删除?
// Copying the data to a new array.
$item_meta_meta_arr = $item_meta->meta;
unset($item_meta_meta_arr['Pickup Location']);
// Checking that it has correctly be unset from the array:
foreach($item_meta_meta_arr as $key => $value)
{
echo 'Key: '. $key . ' / Value: ' . $value . '<br />';
}
if(!is_string($item_meta->meta) )
{
foreach($item_meta->meta as $key1 => $value1)
{
if (is_string($value1)) echo $key1 . $value1 . ' (level 1 - string)<br />';
elseif ( is_array($value1) || is_object($value1) )
{
echo $key1 . ' (level 1 - array)<br />';
foreach($value1 as $key2 => $value2) {
{
if (is_string($value2)) echo $key2 . $value2 . ' (level 2 - string)<br />';
elseif ( is_array($value2) || is_object($value2) )
{
echo $key2 . ' (level 2 - array)<br />';
foreach($value2 as $key3 => $value3) {
{
if (is_string($value3)) echo $key3 . $value3 . ' (level 3 - string)<br />';
}
}
}
}
}
}
echo var_dump( $item_meta );
// Or
foreach ($item_meta as $value)
echo var_dump( $value );
// Or
foreach ($item_meta->meta as $value)
echo var_dump( $value );