当前位置: 首页>>代码示例>>PHP>>正文


PHP WC_Product_Variation::get_image_id方法代码示例

本文整理汇总了PHP中WC_Product_Variation::get_image_id方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Product_Variation::get_image_id方法的具体用法?PHP WC_Product_Variation::get_image_id怎么用?PHP WC_Product_Variation::get_image_id使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WC_Product_Variation的用法示例。


在下文中一共展示了WC_Product_Variation::get_image_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_images

 /**
  * Get the images for a product or product variation
  *
  * @since 2.1
  * @param WC_Product|WC_Product_Variation $product
  * @return array
  */
 private function get_images($product)
 {
     $images = $attachment_ids = array();
     $product_image = $product->get_image_id();
     // Add featured image.
     if (!empty($product_image)) {
         $attachment_ids[] = $product_image;
     }
     // add gallery images.
     $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids());
     // Build image data.
     foreach ($attachment_ids as $position => $attachment_id) {
         $attachment_post = get_post($attachment_id);
         if (is_null($attachment_post)) {
             continue;
         }
         $attachment = wp_get_attachment_image_src($attachment_id, 'full');
         if (!is_array($attachment)) {
             continue;
         }
         $images[] = array('id' => (int) $attachment_id, 'created_at' => $this->server->format_datetime($attachment_post->post_date_gmt), 'updated_at' => $this->server->format_datetime($attachment_post->post_modified_gmt), 'src' => current($attachment), 'title' => get_the_title($attachment_id), 'alt' => get_post_meta($attachment_id, '_wp_attachment_image_alt', true), 'position' => $position);
     }
     // Set a placeholder image if the product has no images set.
     if (empty($images)) {
         $images[] = array('id' => 0, 'created_at' => $this->server->format_datetime(time()), 'updated_at' => $this->server->format_datetime(time()), 'src' => wc_placeholder_img_src(), 'title' => __('Placeholder', 'woocommerce'), 'alt' => __('Placeholder', 'woocommerce'), 'position' => 0);
     }
     return $images;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:35,代码来源:class-wc-api-products.php

示例2: get_images

 /**
  * Get the images for a product or product variation.
  *
  * @param WC_Product|WC_Product_Variation $product Product instance.
  * @return array
  */
 protected function get_images($product)
 {
     $images = array();
     $attachment_ids = array();
     // Add featured image.
     if (has_post_thumbnail($product->get_id())) {
         $attachment_ids[] = $product->get_image_id();
     }
     // Add gallery images.
     $attachment_ids = array_merge($attachment_ids, $product->get_gallery_image_ids());
     // Build image data.
     foreach ($attachment_ids as $position => $attachment_id) {
         $attachment_post = get_post($attachment_id);
         if (is_null($attachment_post)) {
             continue;
         }
         $attachment = wp_get_attachment_image_src($attachment_id, 'full');
         if (!is_array($attachment)) {
             continue;
         }
         $images[] = array('id' => (int) $attachment_id, 'date_created' => wc_rest_prepare_date_response($attachment_post->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($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), 'position' => (int) $position);
     }
     // Set a placeholder image if the product has no images set.
     if (empty($images)) {
         $images[] = array('id' => 0, 'date_created' => wc_rest_prepare_date_response(current_time('mysql')), 'date_modified' => wc_rest_prepare_date_response(current_time('mysql')), 'src' => wc_placeholder_img_src(), 'name' => __('Placeholder', 'woocommerce'), 'alt' => __('Placeholder', 'woocommerce'), 'position' => 0);
     }
     return $images;
 }
开发者ID:shivapoudel,项目名称:woocommerce,代码行数:34,代码来源:class-wc-rest-products-controller.php


注:本文中的WC_Product_Variation::get_image_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。