在订单项目视图中显示自定义产品数据 [英] Displaying custom product data in Order items view

查看:73
本文介绍了在订单项目视图中显示自定义产品数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对添加到购物车有疑问。我有一个具有不同自定义条件的产品可供选择。客户选择特定选项时。它添加到购物车。当客户选择另一个选择并添加时。它显示为购物车中的第二项。没关系但是付款后,订单显示项目1和项目2下的自定义选项,而没有自定义数据。

I have a issue with add to cart. I have a product with different custom conditions to choose. When the customer selects a specific choice. it adds to the cart. When the customer choice another choice and adds. Its shows as a second item in the cart. Which is okay. But after the payment, the order shows the both the custom option under the item 1 and item 2 without the custom data.

所以我在想,而不是显示相同的产品作为不同的项目。我想更新产品自定义数据,因此它将始终显示为单个项目。

so I was thinking instead of showing the same product as different items. I want to update the product custom data, so it will always show as single item.

(注意:我已从管理员启用了单独出售选项,但可以使用)。

如果不能告诉我如何正确显示订单,那么付款后发送的电子邮件将正确显示订单页面。

If not can you tell me how to show in the order correctly, so the email sent after payment, orders page will be shown correctly.

注意:我正在使用的自定义数据是位置和日期。

NOTE: The custom data I am using is loc and date.

请先谢谢您。

推荐答案

更新:


请参阅以下相关问题(实际示例) :

See this recent related questions (Real working examples):

  • Adding user custom field value to order items details
  • Add custom Product data dynamically as item meta data on the Order

因此,您首先需要按订单项中的显示值设置产品属性,以获取该值的清晰显示标签。然后,必须在相关产品中为该属性设置任何值(这些强制性属性值将由您的海关值替换。

So you need first to set a product attribute by displayed value in your Orders items, to get a clean displayed label for this value. Then you have to set this attributes with any value in your related products (These mandatories attributes values are going to be replaced by your customs values.

因此,如果您的属性名称为例如,主要选择将在以下位置设置 pa_primary-choice

So if your attribute Name is "Primary choice" (for example) you will set pa_primary-choice in:

wc_add_order_item_meta($item_id, 'pa_primary-choice', $custom_field_value, true);

然后,您将在商品标题项下方的定额商品中获得带有您自定义字段值(此处 XXXX是您显示的自定义字段值)的标签名称

Then you will get in your orders items detais below product title item the label name with your custom field value (here "XXXX" is your displayed custom field value):

Primary choice: XXXX






对不起,但是您的问题不是很清楚,也不是很详细,也没有使用任何代码,我想您正在谈论的是您自定义的产品自定义字段已经为您的可变产品设置了商品,并反映在购物车对象项上。


Sorry, but as your question is not really clear, not very detailed and without any code that you are using. I suppose that you are talking about product custom fields that you have set for your variable products and that are reflected on cart object items.

Yo您可能需要一些其他代码来将此信息添加为元数据,以便可以将其视为订单的一部分。您可以尝试以下操作,根据数据在产品页面,购物车上以及在结帐时提交的方式来修改代码

You might need some additional code to add this information as meta data so that it can be seen as part of the order. You can try something like below, adapting the code depending on how the data is set in your products page, on cart and submitted in checkout

add_action('woocommerce_add_order_item_meta','add_custom_values_to_order_item_meta', 1, 3 );
function add_custom_values_to_order_item_meta( $item_id, $values, $cart_item_key ) {

    $custom_field1 = $_POST['my_custom_field1_key'];
    // or $values['my_custom_field1_key'];
    $custom_field2 = $_POST['my_custom_field2_key'];
    // or $values['my_custom_field2_key'];

    if ( !empty($custom field1) ) 
        wc_add_order_item_meta($item_id, 'custom_meta_key1', $custom_field1, true);

    if ( !empty($custom field2) ) 
        wc_add_order_item_meta($item_id, 'custom_meta_key2', $custom_field2, true);

    // And so on …
}




对于产品变型来说,它更加复杂,如果您想为每件商品弄些干净的东西,我的意思是标题是您自定义选择字段的值。目前,您所提供的信息和所使用的代码尚不能为您提供更多帮助……

For product variations it's more complicated, if you want to get something clean for each item, I mean a title with the value of your custom chosen field. For the moment with the provided information and used code in your question is not possible to help you more than that…

代码会出现在您活动的子主题(或主题)的function.php文件或任何插件文件中。

对于单独出售 ,您可以使用 woocommerce_is_sold_individually 挂钩来删除数量前端来自产品的设置:

For "Sold Individually", what you can do is to use woocommerce_is_sold_individually hook that will remove quantity front end settings from products:

add_filter( 'woocommerce_is_sold_individually', '__return_true' );

代码会进入您的活动子主题(或主题)的function.php文件中,或者在任何插件文件中。

这篇关于在订单项目视图中显示自定义产品数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆