简体   繁体   English

Woocommerce - 在订单中为产品添加序列

[英]Woocommerce - add serial to products in orders

I am looking for a way to add a serial number to each sold product, in the order display in WooCommerce. 我正在寻找一种方法来为每个销售的产品添加一个序列号,在WooCommerce的订单显示中。 What I need is a manual solution, where the S/N of the sent product is added to the order before the package is sent. 我需要的是一个手动解决方案,其中发送产品的S / N在发送包之前被添加到订单中。 I have tried to show it on the following picture: 我试图在下面的图片上显示它:

添加序列的可能性

Originally, I thought about implementing it as a product meta (without really knowing how) but I realized that product metas can only be altered when the order is set on hold and not while processing. 最初,我考虑将其作为产品元实现(不知道如何),但我意识到只有在订单被设置为保持而不是处理时才能更改产品元数据。

Any ideas aboout how to proceed? 关于如何进行的任何想法? Thanks already! 谢谢!

Not really sure what your trying to achieve but if you need a serial number for each product (just to display it in your cart page) you can add that data as an attribute to each listing then recall it in the checkout area and have it display using hooks. 不确定您想要实现的目标,但如果您需要每个产品的序列号(只是在购物车页面中显示),您可以将该数据作为属性添加到每个商品中,然后在结帐区域调用它并让它显示使用钩子。 How do you want to process the serial number? 您想如何处理序列号? is it purely for display on checkout? 它是纯粹用于结账时显示吗? assuming it is... 假设它是......

add_filter( 'woocommerce_cart_item_name', recall_serial_number, 10, 2 );

function recall_serial_number() {
    $serial = $item_data->get_attributes( 'serial-number' );    
    echo $serial;
}

Give this code a whirl if all you want to do is display the serial on the cart page without processing it any further. 如果你想要做的只是在购物车页面上显示序列而不进一步处理它,请给这个代码一个旋转。 Make sure the name of the attribute is "Serial Number" not tested but should work. 确保属性的名称是“序列号”未经测试但应该有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM