WooCommerce 的 API v2 向产品添加属性 [英] API v2 of WooCommerce add attributes to Product

查看:49
本文介绍了WooCommerce 的 API v2 向产品添加属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 WooCommerce Wc_API_Client 的 API v2 添加产品以将以下代码存储在以下代码中 我不知道我哪里出错了我的以下属性部分没有向我拥有的产品添加属性按名称颜色创建了一个属性,并有选项红色和白色,一切似乎都运行良好,要添加产品,但该属性未包含

I am trying to add a Product via API v2 of WooCommerce Wc_API_Client to wp-store the Below code in the below code i have no idea where am i going wrong my below attributes section is not adding attributes to the products thow i have created a attribute by name Color and has options Red And white everything seem to be working good the product is to added but the attribute is the one was not included

   print_r( $client->products->create( array( 'title' => 'Franky9','sku' => 'Franky9', 'type' => 'simple', 'regular_price' => '1000', 'short_description'=>'short description', 'attributes' => Array ('name'=>'pa_color','options'=>'Red' ) )  ) ) ;

推荐答案

我正在使用 kloon-WooCommerce-REST-API-Client-Library.如果你想用于 wc-api v3.我通读了 class-wc-api-authentication.php 中的身份验证过程,发现不同之处在于我需要附加一个未编码的 &在使用它对我的参数字符串进行签名之前,先使用消费者秘密.

I am using kloon-WooCommerce-REST-API-Client-Library. If you want to use for wc-api v3. I read through the authentication process in class-wc-api-authentication.php and found the difference was I needed to append an unencoded & to the consumer secret before using it to sign my parameter string.

$secret = $consumer_secret . '&';

同时将路径更改为 v3:

Also change the path to v3:

$path .= '/wc-api/v3/';

这篇关于WooCommerce 的 API v2 向产品添加属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆