简体   繁体   English

将元字段添加到产品 shopify

[英]add metafields to product shopify

I have added product metafields to my shopify and is giving success response but are not displayed on the product details.我已将产品元字段添加到我的 shopify 并给出成功响应,但未显示在产品详细信息中。 here is my nodejs code which is giving success response.这是我的 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();

Basically, I want is when user/customer click on product there should be a new field in product that is type.基本上,我想要的是当用户/客户点击产品时,产品中应该有一个新的类型字段。 Can anyone help me how to display it.任何人都可以帮助我如何显示它。

The metafields object allows you to store additional information for products, collections, customers, orders, blogs, pages and your shop.元字段对象允许您存储产品、系列、客户、订单、博客、页面和您的商店的附加信息。

In your case, you have already created Metafield and now just want to display it on product page.在您的情况下,您已经创建了 Metafield,现在只想在产品页面上显示它。 To do so, you need to use metafield property on Product object.为此,您需要在 Product 对象上使用元字段属性。 To access the metafield that your code created, add the following code to product page in Shopify theme.要访问您的代码创建的元字段,请将以下代码添加到 Shopify 主题中的产品页面。

{{product.metafields.type.type}}

The first type is your namespace while the type after that is field name.第一种类型是您的命名空间,而后一种类型是字段名称。

To read more about how to add, edit and display Metafield, follow Shopify Docs for Metafields .要了解有关如何添加、编辑和显示 Metafield 的更多信息,请按照Shopify Docs for Metafields 进行操作

For Shopify Plus account, Yes it is possible to add fields.对于 Shopify Plus 帐户,是的,可以添加字段。 But you will not be able to access the Shopify form elements in Liquid as those are rendered via tag.但是您将无法访问 Liquid 中的 Shopify 表单元素,因为这些元素是通过标签呈现的。 However, you can add custom JS file.但是,您可以添加自定义 JS 文件。 So on page load, anything is possible.所以在页面加载时,一切皆有可能。

You can have a look at basic docs for editing checkout.liquid .您可以查看用于编辑checkout.liquid 的基本文档。 However, to edit checkout forms and things like that, it is mostly JavaScript with plenty of answers on StackOverflow.但是,要编辑结帐表格之类的东西,主要是 JavaScript,在 StackOverflow 上有很多答案。

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

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