将元字段添加到产品 shopify
add metafields to product shopify
我已将产品元字段添加到我的 shopify 并给出成功响应,但未显示在产品详细信息中。这是我的 nodejs 代码,它给出了成功响应。
const response = await fetch(`https://mystore.myshopify.com/admin/api/2020-07/products/5709040025760/metafields.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
"X-Shopify-Access-Token": accessToken,
},
body: JSON.stringify({
"metafield": {
"namespace": "type",
"key": "type",
"value": "test type",
"value_type": "string"
}
})
})
const responseJson = await response.json();
基本上,我想要的是当 user/customer 单击产品时,产品中应该有一个新字段,即类型。谁能帮我看看怎么显示。
The metafields object allows you to store additional information for
products, collections, customers, orders, blogs, pages and your shop.
在您的例子中,您已经创建了 Metafield,现在只想在产品页面上显示它。为此,您需要在 Product 对象上使用元字段 属性。要访问您的代码创建的元字段,请将以下代码添加到 Shopify 主题中的产品页面。
{{product.metafields.type.type}}
第一个 type 是您的命名空间,而后面的 type 是字段名称。
要了解有关如何添加、编辑和显示元字段的更多信息,请关注 Shopify Docs for Metafields。
对于 Shopify Plus 帐户,可以添加字段。但是您将无法访问 Liquid 中的 Shopify 表单元素,因为这些元素是通过标签呈现的。但是,您可以添加自定义 JS 文件。所以在页面加载时,一切皆有可能。
您可以查看编辑的基本文档checkout.liquid。但是,要编辑结帐表格和类似的东西,主要是 JavaScript 在 Whosebug 上有很多答案。
我已将产品元字段添加到我的 shopify 并给出成功响应,但未显示在产品详细信息中。这是我的 nodejs 代码,它给出了成功响应。
const response = await fetch(`https://mystore.myshopify.com/admin/api/2020-07/products/5709040025760/metafields.json`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
"X-Shopify-Access-Token": accessToken,
},
body: JSON.stringify({
"metafield": {
"namespace": "type",
"key": "type",
"value": "test type",
"value_type": "string"
}
})
})
const responseJson = await response.json();
基本上,我想要的是当 user/customer 单击产品时,产品中应该有一个新字段,即类型。谁能帮我看看怎么显示。
The metafields object allows you to store additional information for products, collections, customers, orders, blogs, pages and your shop.
在您的例子中,您已经创建了 Metafield,现在只想在产品页面上显示它。为此,您需要在 Product 对象上使用元字段 属性。要访问您的代码创建的元字段,请将以下代码添加到 Shopify 主题中的产品页面。
{{product.metafields.type.type}}
第一个 type 是您的命名空间,而后面的 type 是字段名称。
要了解有关如何添加、编辑和显示元字段的更多信息,请关注 Shopify Docs for Metafields。
对于 Shopify Plus 帐户,可以添加字段。但是您将无法访问 Liquid 中的 Shopify 表单元素,因为这些元素是通过标签呈现的。但是,您可以添加自定义 JS 文件。所以在页面加载时,一切皆有可能。
您可以查看编辑的基本文档checkout.liquid。但是,要编辑结帐表格和类似的东西,主要是 JavaScript 在 Whosebug 上有很多答案。