WC_REST_Product_Variations_Controller::get_image()
Get the image for a product variation.
Метод класса: WC_REST_Product_Variations_Controller{}
Хуков нет.
Возвращает
Массив
.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_image( $variation, $context );
- $variation(WC_Product_Variation) (обязательный)
- Variation data.
- $context(строка)
- Context of the request: 'view' or 'edit'.
По умолчанию: 'view'
Код WC_REST_Product_Variations_Controller::get_image() WC REST Product Variations Controller::get image WC 8.7.0
protected function get_image( $variation, $context = 'view' ) { if ( ! $variation->get_image_id( $context ) ) { return; } $attachment_id = $variation->get_image_id(); $attachment_post = get_post( $attachment_id ); if ( is_null( $attachment_post ) ) { return; } $attachment = wp_get_attachment_image_src( $attachment_id, 'full' ); if ( ! is_array( $attachment ) ) { return; } if ( ! isset( $image ) ) { return array( 'id' => (int) $attachment_id, 'date_created' => wc_rest_prepare_date_response( $attachment_post->post_date, false ), 'date_created_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_date_gmt ) ), 'date_modified' => wc_rest_prepare_date_response( $attachment_post->post_modified, false ), 'date_modified_gmt' => wc_rest_prepare_date_response( strtotime( $attachment_post->post_modified_gmt ) ), 'src' => current( $attachment ), 'name' => get_the_title( $attachment_id ), 'alt' => get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ), ); } }