[使用woocommerce api创建客户时如何将自定义字段添加为元数据

问题描述 投票:0回答:1

首先,我的模型中有一个名为afm的字段。

我发现在创建客户的过程中很难在其他字段之间发布此字段的值。

创建客户实例的过程是从我的Django应用程序执行的。创建实例后,实例(在发布后)在网站管理面板的woocommerce-> users部分中也是可见的。

自定义元字段具有键:wholesale_afm

如何将这个自定义字段放入数据字典中?以下是我未成功的尝试。

def create_woocommerce_client_individually(wcapi,name,surname,username,email,afm):


        data = {

            "first_name": name,    
            "last_name": surname,
            "username": username,
            "email": email,
            "meta":{
            "wholesale_afm":"afm",
            }
            }
        wcapi.post("customers", data).json()
        print("storing the client to woocommerce website...\n")
python django woocommerce metadata woocommerce-rest-api
1个回答
0
投票

最后,在搜索之后,我想出了如何为woocommerce产品更新自定义元字段的值。

谈论用户(客户)时,发生相同的过程。

在更新部分中,必须在包含数据的字典内添加该部分:

"meta_data": [{"id": cid, "key": "wholesale_afm", "value": afm }],

其中:

cid:从woocommerce站点提供给每个客户的客户ID

键:定义的键(通常在functions.php中创建)

值:从该字段的客户记录中获取的值

© www.soinside.com 2019 - 2024. All rights reserved.