【发布时间】:2016-12-22 09:21:45
【问题描述】:
我在尝试过滤客户下订单后发送到电子邮件中的某些数据时遇到了很大的困难。问题是每个订单项都显示运输信息(取货地点),即使它与订单结束时的最终取货地点相同。
我已经能够查看给出的 item_meta 数据,但我不确定如何过滤它以从根本上删除具有“拾取位置”元键的数组部分,然后仍然打印其余部分。这里是生成数据的 email-order-items.php 文件区域(不是自定义的……这是 WooCommerce 的标准):
if ( ! empty( $item_meta->meta ) ) {
echo '<br/><small>' . nl2br( $item_meta->display( true, true, '_', "\n" ) ) . '</small>';
}
这是我通过简单的操作就能看到的:
foreach ($item_meta as $value) {
print_r($value);
}
结果:
Cookie → Cookie (One-Time)Array ( [_qty] => Array ( [0] => 1 ) [_tax_class] => 数组 ( [0] => ) [_product_id] => 数组 ( [0] => 5807 ) [_variation_id] => 数组 ( [0] => 0 ) [_line_subtotal] => 数组 ( [0] => 2.5 ) [_line_total] => 数组 ( [0] => 0 ) [_line_subtotal_tax] => 数组 ( [0] => 0.15 ) [_line_tax] => 数组 ( [0] => 0 ) [_line_tax_data] => 数组 ( [0] => a:2:{s:5:"总计";a:1:{i:1;s:1:"0";}s:8:"小计";a:1:{i:1;s: 4:“0.15”;}} ) [_shipping_item_id] => 数组 ([0] => 28795) [取货地点] => 数组([0] => 取件地址,城市,州,邮编)) WC_Product_Simple 对象([id] => 5807 [post] => WP_Post 对象( [ID] => 5807 [post_author] => 596 [post_date] => 2016-07-23 17:55:10 [post_date_gmt] => 2016-07-23 21:55:10 [post_content] => [post_title] => 强力蛋白饼干(一次性)[post_excerpt] => [post_status] => 发布 [comment_status] => 关闭 [ping_status] => 关闭 [post_password] => [post_name] => power-protein-cookie-one-time [to_ping] => [pinged] => [post_modified] => 2016-07-23 19:39:18 [post_modified_gmt] => 2016-07-23 23:39:18 [post_content_filtered] => [post_parent] => 5806 [menu_order] => 1 [post_type] => 产品 [post_mime_type] => [comment_count] => 0 [filter] => raw) [product_type] => 简单 [shipping_class:protected] => [shipping_class_id:protected] => 0 ) ]
如何遍历 item_meta 数据,取消设置(我认为是这样做的方法)Pickup Location 数据,然后仍然显示其余部分?
更新:我进去并尝试了以下代码:
if(is_array($item_meta->meta))
{
foreach($item_meta->meta as $key => $value)
{
echo $key . '<br />' . $value;
}
}
这给了我以下信息:
Cookie → Cookie(一次性)_qty Array_tax_class Array_product_id Array_variation_id Array_line_subtotal Array_line_total Array_line_subtotal_tax Array_line_tax Array_line_tax_data Array_shipping_item_id ArrayPickup 位置 数组
我觉得我很接近,但不太了解 item_meta 内部的结构......任何帮助将不胜感激。
【问题讨论】:
标签: php wordpress cookies woocommerce metadata