'[main_gallery image-number="1" use_main_if_no_gallery=true]', ); public $display_name = 'Main gallery image url'; public function getValue($post, $field) { $imageSize = get_option(Database::$optionPostImageSize, 'medium'); $galleryImageIndex = isset($field['args']['image-number']) && !empty(intval($field['args']['image-number'])) ? intval($field['args']['image-number']) - 1 : 0; if (in_array($post->post_type, array('product_variation', 'product'))) { $galleryImagesIds = (new \WC_product('product_variation' === $post->post_type ? $post->post_parent : $post->ID))->get_gallery_image_ids(); } else { $galleryImagesIds = array(); } $useMainIfNoGallery = isset($field['args']['use_main_if_no_gallery']) && 'true' === $field['args']['use_main_if_no_gallery']; return isset($galleryImagesIds[$galleryImageIndex]) ? wp_get_attachment_image_url($galleryImagesIds[$galleryImageIndex], $imageSize) : ($useMainIfNoGallery ? $this->getProductImageUrl($post, $field) : Variables::$A4B_PLUGIN_BASE_URL . 'assets/img/no-gallery-image.png'); } }