python,woocommerce:如何添加带有翻译的类别?

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

我需要一个 python 片段来创建带有翻译的类别。 带有 woocommerce 包的 Python 3.8。

带有 woocommerce 插件的 WordPress 7.3 版本

WPML 多语言 CMS:4.5.14

我在 python 中有这个片段:

from woocommerce import API

# create an instance of the API class
wcapi = API(
    url="FQDN",
    consumer_key="yourconsumerkey",
    consumer_secret="yourconsumersecret",
    wp_api=True,
    version="wc/v3"
)

# create a dictionary with the category data for the main language
category_data_en = {
    "name": "Category Name in English",
    "parent": 0,
    "meta_data": [
        {
            "key": "_wpml_language",
            "value": "en"
        },
        {
            "key": "_wpml_translation_status",
            "value": "0"
        },
        {
            "key": "_wpml_element_type",
            "value": "tax_category"
        }
    ]
}

# create the category using the WooCommerce API for the main language
new_category_en = wcapi.post("products/categories", category_data_en).json()

# create a dictionary with the category data for the translation
category_data_pl = {
    "name": "Category Name in Polish",
    "meta_data": [
        {
            "key": "_wpml_language",
            "value": "pl"
        },
        {
            "key": "_wpml_translation_of",
            "value": new_category_en.get("id")
        },
        {
            "key": "_wpml_translation_status",
            "value": "1"
        },
        {
            "key": "_wpml_element_type",
            "value": "tax_category"
        }
    ]
}

# create the translation using the WooCommerce API
new_category_pl = wcapi.post("products/categories", category_data_pl).json()

它在我的网站上用英语创建了两个类别。我究竟做错了什么?

我可以看到在我的 WPML 插件设置中有以下信息: WooCommerce 多语言未安装 是否需要安装它才能正确创建这些类别?

python wordpress woocommerce wordpress-rest-api wpml
© www.soinside.com 2019 - 2024. All rights reserved.