我正在使用WooCommerce API,但我遇到了请求问题。
有时,API请求会返回404或重定向到" my-account"。
API请求示例:
https://example.com/index.php/wc-api/v3/products?consumer_key=ck_XXXXXXXXX&consumer_secret=cs_XXXXXXXXX`.
启用漂亮的链接。
这是我的.htacess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
有什么想法吗?
答案 0 :(得分:1)
请从此处下载SDK:https://packagist.org/packages/automattic/woocommerce 并从这里获取指导:https://woothemes.github.io/woocommerce-rest-api-docs/。 并创建api凭证表格wordpress admin end woocommerce&gt;设置&gt;添加新密钥
$client = 'ck_63aade4xxxxxxxxxxxxxxx'; //put client key
$secret = 'cs_673d7cdxxxxxxxxxxxxxxx'; //put secret key
require __DIR__ . '/restapi/vendor/autoload.php'; //give your sdk autoload.php path
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'http://localhost:8888/woocommerce/', //site url
$client,
$secret, // Your consumer secret
[
'version' => 'v3' // WooCommerce API version
]
);
print_r($woocommerce->get(''));