我目前正在研究一些与woocommerce_order_status_completed钩子一起运行的代码。该代码将连接到第三方,以检索购买的物品的序列号。本来我打算只是把系列邮件发送给客户,但我想知道,是否可以将检索到的序列号添加到订购商品(元?),以便当客户访问他们的账户页面查看订单时,他们看到那里列出的序列号(即购买的产品(第)下?添加自定义订单项元数据
这是可能一些如何?将信息添加到要想在帐户页面上显示?
我目前正在研究一些与woocommerce_order_status_completed钩子一起运行的代码。该代码将连接到第三方,以检索购买的物品的序列号。本来我打算只是把系列邮件发送给客户,但我想知道,是否可以将检索到的序列号添加到订购商品(元?),以便当客户访问他们的账户页面查看订单时,他们看到那里列出的序列号(即购买的产品(第)下?添加自定义订单项元数据
这是可能一些如何?将信息添加到要想在帐户页面上显示?
当然,添加它像这样:
function add_order_item_meta($item_id, $values) {
$key = ''; // Define your key here
$value = ''; // Get your value here
woocommerce_add_order_item_meta($item_id, $key, $value);
}
add_action('woocommerce_add_order_item_meta', 'add_order_item_meta', 10, 2);
如果使用类:
add_action('woocommerce_add_order_item_meta', array($this,'add_order_item_meta'), 10, 2);
public static function add_order_item_meta($item_id, $values) {
$key = 'statusitem'; // Define your key here
$value = 'AAA'; // Get your value here
wc_update_order_item_meta($item_id, $key, $value);
}
如果不使用类:从API
add_action('woocommerce_add_order_item_meta', 'add_order_item_meta', 10, 2);
function add_order_item_meta($item_id, $values) {
$key = 'statusitem'; // Define your key here
$value = 'AAA'; // Get your value here
wc_update_order_item_meta($item_id, $key, $value);
}
JSON响应号召,看meta_data:
"line_items": [{
"id": 425,
"name": "FANTA",
"product_id": 80,
"variation_id": 0,
"quantity": 1,
"tax_class": "",
"subtotal": "30000.00",
"subtotal_tax": "0.00",
"total": "30000.00",
"total_tax": "0.00",
"taxes": [],
"meta_data": [{
"id": 3079,
"key": "statusitem",
"value": "AAA"
}],
"sku": "000000000000009",
"price": 30000
}],
你也可以得到这个函数的车项目密钥,添加第三个参数。请参阅http://hookr.io/actions/woocommerce_add_order_item_meta/ –
它是否为订单项的meta_data添加数据? – Jeboy