WC_Brands::rest_api_prepare_brands_to_product()publicWC 1.0

Prepare brands in product response.

Метод класса: WC_Brands{}

Хуков нет.

Возвращает

WP_REST_Response.

Использование

$WC_Brands = new WC_Brands();
$WC_Brands->rest_api_prepare_brands_to_product( $response, $post );
$response(WP_REST_Response) (обязательный)
The response object.
$post(WP_Post|WC_Data) (обязательный)
Post object or WC object.

Код WC_Brands::rest_api_prepare_brands_to_product() WC 9.4.2

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;
}