首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >woocommerce api回音响应

woocommerce api回音响应
EN

WordPress Development用户
提问于 2021-07-30 08:16:06
回答 1查看 148关注 0票数 0

抛出woocommerce api我发布了一个产品到wordpress网站,但是我想检索响应,因为现在我只想打印响应。

使用php如果我使用print_r($woocommerce->http),我得到上面的内容

代码语言:javascript
复制
Automattic\WooCommerce\HttpClient\HttpClient Object
(
    [ch:protected] => Resource id #7
    [url:protected] => https://mywebsite.com/wp-json/wc/v3/
    [consumerKey:protected] => ck_123456789789789789789789
    [consumerSecret:protected] => cs_123456789789789789789789
    [options:protected] => Automattic\WooCommerce\HttpClient\Options Object
        (
            [options:Automattic\WooCommerce\HttpClient\Options:private] => Array
                (
                    [wp_api] => 1
                    [version] => wc/v3
                    [verify_ssl] => 
                )

        )

    [request:Automattic\WooCommerce\HttpClient\HttpClient:private] => Automattic\WooCommerce\HttpClient\Request Object
        (
            [url:Automattic\WooCommerce\HttpClient\Request:private] => https://mywebsite/wp-json/wc/v3/products
            [method:Automattic\WooCommerce\HttpClient\Request:private] => POST
            [parameters:Automattic\WooCommerce\HttpClient\Request:private] => Array
                (
                )

            [headers:Automattic\WooCommerce\HttpClient\Request:private] => Array
                (
                    [Accept] => application/json
                    [User-Agent] => WooCommerce API Client-PHP/3.0.0
                    [Content-Type] => application/json;charset=utf-8
                )

            [body:Automattic\WooCommerce\HttpClient\Request:private] => {"name":"P\u00e1la","type":"simple","regular_price":"100","short_description":"","stock_quantity":"1","manage_stock":true,"categories":[{"id":37}],"images":[{"src":"https:\/\/mywebsite\/wp-content\/uploads\/img2.jpg"}]}
        )

    [response:Automattic\WooCommerce\HttpClient\HttpClient:private] => Automattic\WooCommerce\HttpClient\Response Object
        (
            [code:Automattic\WooCommerce\HttpClient\Response:private] => 201
            [headers:Automattic\WooCommerce\HttpClient\Response:private] => Array
                (
                    [server] => nginx
                    [date] => Fri, 30 Jul 2021 08:04:11 GMT
                    [content-type] => application/json; charset=UTF-8
                    [location] => https://mywebsite/wp-json/wc/v3/products/752
                    [x-powered-by] => PHP/7.4.21
                    [x-robots-tag] => noindex
                    [link] => ; rel="https://api.w.org/"
                    [x-content-type-options] => nosniff
                    [access-control-expose-headers] => X-WP-Total, X-WP-TotalPages, Link
                    [access-control-allow-headers] => Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
                    [expires] => Wed, 11 Jan 1984 05:00:00 GMT
                    [cache-control] => no-cache, must-revalidate, max-age=0
                    [allow] => GET, POST
                    [x-scale] => YXBvY2FzQGdpdGh1Yg==
                )

            [body:Automattic\WooCommerce\HttpClient\Response:private] => {"id":752,"name":"P\u00e1la","slug":"pala-11","permalink":"https:\/\/mywebsite\/produto\/pala-11\/","date_created":"2021-07-30T08:04:11","date_created_gmt":"2021-07-30T08:04:11","date_modified":"2021-07-30T08:04:11","date_modified_gmt":"2021-07-30T08:04:11","type":"simple","status":"publish","featured":false,"catalog_visibility":"visible","description":"","short_description":"","sku":"","price":"100","regular_price":"100","sale_price":"","date_on_sale_from":null,"date_on_sale_from_gmt":null,"date_on_sale_to":null,"date_on_sale_to_gmt":null,"on_sale":false,"purchasable":true,"total_sales":0,"virtual":false,"downloadable":false,"downloads":[],"download_limit":-1,"download_expiry":-1,"external_url":"","button_text":"","tax_status":"taxable","tax_class":"","manage_stock":true,"stock_quantity":1,"backorders":"no","backorders_allowed":false,"backordered":false,"low_stock_amount":null,"sold_individually":false,"weight":"","dimensions":{"length":"","width":"","height":""},"shipping_required":true,"shipping_taxable":true,"shipping_class":"","shipping_class_id":0,"reviews_allowed":true,"average_rating":"0","rating_count":0,"upsell_ids":[],"cross_sell_ids":[],"parent_id":0,"purchase_note":"","categories":[{"id":37,"name":"destaques","slug":"destaques"}],"tags":[],"images":[{"id":751,"date_created":"2021-07-30T08:04:11","date_created_gmt":"2021-07-30T08:04:11","date_modified":"2021-07-30T08:04:11","date_modified_gmt":"2021-07-30T08:04:11","src":"https:\/\/mywebsite\/wp-content\/uploads\/img2.jpg","name":"img2.jpg","alt":""}],"attributes":[],"default_attributes":[],"variations":[],"grouped_products":[],"menu_order":0,"price_html":"100.00€<\/span><\/bdi><\/span>","related_ids":[386,404,673,743,684],"meta_data":[],"stock_status":"instock","_links":{"self":[{"href":"https:\/\/mywebsite\/wp-json\/wc\/v3\/products\/752"}],"collection":[{"href":"https:\/\/imobus.pt\/wp-json\/wc\/v3\/products"}]}}
        )

    [responseHeaders:Automattic\WooCommerce\HttpClient\HttpClient:private] => HTTP/2 201 
server: nginx
date: Fri, 30 Jul 2021 08:04:11 GMT
content-type: application/json; charset=UTF-8
location: https://mywebsite/wp-json/wc/v3/products/752
x-powered-by: PHP/7.4.21
x-robots-tag: noindex
link: ; rel="https://api.w.org/"
x-content-type-options: nosniff
access-control-expose-headers: X-WP-Total, X-WP-TotalPages, Link
access-control-allow-headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Type
expires: Wed, 11 Jan 1984 05:00:00 GMT
cache-control: no-cache, must-revalidate, max-age=0
allow: GET, POST
x-scale: YXBvY2FzQGdpdGh1Yg==


)

我想使用body:Automattic\WooCommerce\HttpClient\Response:private数组,那么如何打印它呢?

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2021-07-30 08:28:25

找到了!谢谢!

代码语言:javascript
复制
echo '<pre>';
  print_r($woocommerce->http->getResponse()->getbody());
echo '</pre>';
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/392671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档