WC_Brands::rest_api_add_brands_to_product()
Add brands in product response.
Метод класса: WC_Brands{}
Хуков нет.
Возвращает
null
. Ничего (null).
Использование
$WC_Brands = new WC_Brands(); $WC_Brands->rest_api_add_brands_to_product( $product, $request, $creating );
- $product(WC_Data) (обязательный)
- Inserted product object.
- $request(WP_REST_Request) (обязательный)
- Request object.
- $creating(true|false)
- True when creating object, false when updating.
По умолчанию: true
Код WC_Brands::rest_api_add_brands_to_product() WC Brands::rest api add brands to product WC 9.4.2
public function rest_api_add_brands_to_product( $product, $request, $creating = true ) { $product_id = is_callable( array( $product, 'get_id' ) ) ? $product->get_id() : ( ! empty( $product->ID ) ? $product->ID : null ); $params = $request->get_params(); $brands = isset( $params['brands'] ) ? $params['brands'] : array(); if ( ! empty( $brands ) ) { if ( is_array( $brands[0] ) && array_key_exists( 'id', $brands[0] ) ) { $brands = array_map( function ( $brand ) { return absint( $brand['id'] ); }, $brands ); } else { $brands = array_map( 'absint', $brands ); } wp_set_object_terms( $product_id, $brands, 'product_brand' ); } }