Reputation: 1
I am using WooCommerce with WC Vendors plugin. I am trying to return vendor name and id when returning the product list through the API call (/wp-json/wc/v3/products
)
I have been advised to use the following code in functions.php:
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 );
The data I get does not contain either the vendor_id or vendor_name.
Upvotes: 0
Views: 1023
Reputation: 60
Adding this code to your theme’s functions.php file:
if ( post_type_exists( 'product' ) ) {
add_post_type_support( 'product', 'author' );
}
Hope it helps you out!
Upvotes: 1