WC_Brands::rest_api_prepare_brands_to_product
Prepare brands in product response.
Method of the class: WC_Brands{}
No Hooks.
Returns
WP_REST_Response.
Usage
$WC_Brands = new WC_Brands(); $WC_Brands->rest_api_prepare_brands_to_product( $response, $post );
- $response(WP_REST_Response) (required)
- The response object.
- $post(WP_Post|WC_Data) (required)
- Post object or WC object.
WC_Brands::rest_api_prepare_brands_to_product() WC Brands::rest api prepare brands to product code WC 10.5.0
public function rest_api_prepare_brands_to_product( $response, $post ) {
$post_id = is_callable( array( $post, 'get_id' ) ) ? $post->get_id() : ( ! empty( $post->ID ) ? $post->ID : null );
if ( empty( $response->data['brands'] ) ) {
$terms = array();
foreach ( wp_get_post_terms( $post_id, 'product_brand' ) as $term ) {
$terms[] = array(
'id' => $term->term_id,
'name' => $term->name,
'slug' => $term->slug,
);
}
$response->data['brands'] = $terms;
}
return $response;
}