WooCommerce REST API 获取作者的产品

WooCommerce REST API get product with author

我可以通过此查询获取产品数据;

https://example.com/wc-api/v2/products/3222?consumer_key=ck_my_key&consumer_secret=cs_my_secret

它returns这样的数据

{
"product": {
    "title": "Guess Capraz Canta",
    "id": 3222,
    "created_at": "2017-06-13T08:33:18Z",
    "updated_at": "2017-06-13T08:33:18Z",
    "type": "simple",
    "status": "publish",
    "downloadable": false,
    "virtual": false,
    "permalink": "https://www.example.com/urun/guess-capraz-canta/",
    "sku": "",
    "price": "150.00",
    "regular_price": "600.00",
    "sale_price": "150.00",
    "price_html": "<del><span class=\"woocommerce-Price-amount amount\">600,00&nbsp;<span class=\"woocommerce-Price-currencySymbol\">&#8378;</span></span></del> <ins><span class=\"woocommerce-Price-amount amount\">150,00&nbsp;<span class=\"woocommerce-Price-currencySymbol\">&#8378;</span></span></ins>",
    "taxable": true,
    "tax_status": "taxable",
    "tax_class": "",
    "managing_stock": true,
    "stock_quantity": 1,
    "in_stock": true,
    "backorders_allowed": false,
    "backordered": false,
    "sold_individually": true,
    "purchaseable": true,
    "featured": false,
    "visible": true,
    "catalog_visibility": "visible",
    "on_sale": true,
    "product_url": "",
    "button_text": "",
    "weight": null,
    "dimensions": {
        "length": "",
        "width": "",
        "height": "",
        "unit": "cm"
    },
    "shipping_required": true,
    "shipping_taxable": true,
    "shipping_class": "",
    "shipping_class_id": null,
    "description": "<p>Guess Capraz Canta<br />\nSiyah<br />\nUrunde asinmalar mevcut( kapak ic derisinde ve capraz aski halkalarinda renk degisimi)</p>\n",
    "short_description": "",
    "reviews_allowed": true,
    "average_rating": "0.00",
    "rating_count": 0,
    "related_ids": [
        2689,
        3087,
        3067,
        2540,
        2785
    ],
    "upsell_ids": [],
    "cross_sell_ids": [],
    "parent_id": 0,
    "categories": [
        "Çapraz Askılı Çanta"
    ],
    "tags": [],
    "images": [
        {
            "id": 3250,
            "created_at": "2017-06-13T08:32:43Z",
            "updated_at": "2017-06-13T08:32:43Z",
            "src": "https://www.example.com/wp-content/uploads/2017/06/Başlıksız9.jpg",
            "title": "basliksiz9",
            "alt": "",
            "position": 0
        },
        {
            "id": 3219,
            "created_at": "2017-06-07T12:51:44Z",
            "updated_at": "2017-06-07T12:51:44Z",
            "src": "https://www.example.com/wp-content/uploads/2017/06/IMG_2880.jpg",
            "title": "img_2880",
            "alt": "",
            "position": 1
        },
        {
            "id": 3220,
            "created_at": "2017-06-07T12:51:54Z",
            "updated_at": "2017-06-07T12:51:54Z",
            "src": "https://www.example.com/wp-content/uploads/2017/06/IMG_2881.jpg",
            "title": "img_2881",
            "alt": "",
            "position": 2
        },
        {
            "id": 3218,
            "created_at": "2017-06-07T12:51:35Z",
            "updated_at": "2017-06-07T12:51:35Z",
            "src": "https://www.example.com/wp-content/uploads/2017/06/IMG_2878.jpg",
            "title": "img_2878",
            "alt": "",
            "position": 3
        },
        {
            "id": 3221,
            "created_at": "2017-06-07T12:52:03Z",
            "updated_at": "2017-06-07T12:52:03Z",
            "src": "https://www.example.com/wp-content/uploads/2017/06/IMG_2882.jpg",
            "title": "img_2882",
            "alt": "",
            "position": 4
        },
        {
            "id": 3217,
            "created_at": "2017-06-07T12:51:05Z",
            "updated_at": "2017-06-07T12:51:05Z",
            "src": "https://www.example.com/wp-content/uploads/2017/06/IMG_2879.jpg",
            "title": "img_2879",
            "alt": "",
            "position": 5
        }
    ],
    "featured_src": "https://www.example.com/wp-content/uploads/2017/06/Başlıksız9.jpg",
    "attributes": [
        {
            "name": "Renk",
            "slug": "renk",
            "position": 0,
            "visible": true,
            "variation": false,
            "options": [
                "Siyah"
            ]
        },
        {
            "name": "Kullanım Durumu",
            "slug": "kullanim-durumu",
            "position": 0,
            "visible": false,
            "variation": false,
            "options": [
                "Ortalama"
            ]
        },
        {
            "name": "Kargo Durumu",
            "slug": "kargo-durumu",
            "position": 0,
            "visible": false,
            "variation": false,
            "options": [
                "Alıcı Öder"
            ]
        }
    ],
    "downloads": [],
    "download_limit": 0,
    "download_expiry": 0,
    "download_type": "",
    "purchase_note": "",
    "total_sales": 0,
    "variations": [],
    "parent": []
}

}

但是由于我的店铺是c2c,所以我需要显示vendor/author的名称。我为多个供应商使用 WC Vendors 插件,供应商信息在 post 作者单元格中。

提前致谢。

是的。我这样解决了问题

    function filter_woocommerce_api_product_response( $product_data, $product, $fields, $this_server ) { 
    $product_data['vendor_id'] = get_post_field( 'post_author', $product->id);
    $product_data['vendor_name'] = get_the_author_meta( 'display_name', $product_data['vendor_id']);
        return $product_data; 


};      
add_filter( 'woocommerce_api_product_response', 'filter_woocommerce_api_product_response', 10, 4 );