使用属性数据更新产品变化

时间:2020-11-08 03:12:24

标签: php wordpress woocommerce code-snippets

我不能很好地考虑如何更新产品变化价格... 我的意思是,我使用简单的代码

来获得变化/参考值(如SKU)和新价格
update_post_meta($post_id, '_regular_price',    $regular_price);
update_post_meta($post_id, '_price',            $regular_price);

问题在于,没有post_id。

例如,我拥有的值只是一个属性数据:

{
  "id": 733,
  "date_modified_gmt": "2020-03-23T03:24:41",
  "description": "",
  "permalink": "https://example.com/product/ship-your-idea/?attribute_pa_color=green",
  "sku": "0001"
....
  },
    "name": "",
    "alt": ""
  },
  "attributes": [
    {
      "id": 6,
      "name": "Reference",
      "option": "*AB001*",
      "price": "*200000*",
    }

  ],...

使用上面的示例,我有[option = AB001],需要更新该价格200000

我能想到的唯一方法是创建一个包含所有产品数据的数组,然后将其与我从Json url获得的数据进行比较

但是我不知道如何读取和存储所有数据以进行比较

谢谢

0 个答案:

没有答案