public static function change_image_in_cart_page($product_image, $values, $cart_item_key) { if (is_array($values) && isset($values['variation_id']) && $values['variation_id'] > 0) { return $product_image; } elseif (isset($values['product_id']) && $values['product_id'] > 0) { $product_id = $values['product_id']; // Don't change the image if product has featured image if (has_post_thumbnail($product_id)) { return $product_image; } $dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids($product_id); if (is_array($dgallery_ids) && count($dgallery_ids) > 0) { // Use first image from variation gallery $img_id = (int) array_shift($dgallery_ids); $product_image = wp_get_attachment_image($img_id, 'shop_thumbnail'); } } return $product_image; }
public function woocommerce_product_image_box() { global $post; $wc_dgallery_hide_woo_gallery = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'hide_woo_gallery', 'no'); $global_wc_dgallery_activate = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'activate'); $actived_d_gallery = get_post_meta($post->ID, '_actived_d_gallery', true); if ($actived_d_gallery == '' && $global_wc_dgallery_activate != 'no') { $actived_d_gallery = 1; } wp_enqueue_style('a3-dynamic-metabox-admin-style'); if (is_rtl()) { wp_enqueue_style('a3-dynamic-metabox-admin-style-rtl'); } wp_enqueue_script('a3-dynamic-metabox-admin-script'); wp_localize_script('a3-dynamic-metabox-admin-script', 'a3_dgallery_metabox', array('ajax_url' => admin_url('admin-ajax.php', 'relative'))); wp_enqueue_media(); ob_start(); ?> <style> #woocommerce-product-images { <?php if ($actived_d_gallery == 1 && $wc_dgallery_hide_woo_gallery == 'yes') { ?> display: none; <?php } else { ?> display: block; <?php } ?> } </style> <div class="a3rev_panel_container a3-metabox-panel-wrap a3-dynamic-metabox-panel-wrap" style="padding-left: 0px;"> <div style="margin-bottom:10px;"> <label class="a3_actived_d_gallery" style="margin-right: 50px;"> <input type="checkbox" <?php checked(1, $actived_d_gallery, true); ?> value="1" name="actived_d_gallery" class="actived_d_gallery" /> <?php echo __('A3 Dynamic Image Gallery activated', 'woo_dgallery'); ?> </label> </div> <div id="main_dgallery_panel" class="dgallery_images_container a3-metabox-panel a3-metabox-options-panel" style="<?php if (1 != $actived_d_gallery) { echo 'display: none;'; } ?> "> <ul class="dgallery_images"> <?php $dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids($post->ID); if (is_array($dgallery_ids) && count($dgallery_ids) > 0) { foreach ($dgallery_ids as $img_id) { $img_data = wp_get_attachment_image_src($img_id, 'thumbnail'); ?> <li class="image" data-attachment_id="<?php echo $img_id; ?> "> <img class="image_item" src="<?php echo $img_data['0']; ?> " /> <ul class="actions"> <li><a href="#" class="delete dg_tips" data-tip="<?php echo __('Delete image', 'woo_dgallery'); ?> "><?php echo __('Delete image', 'woo_dgallery'); ?> </a></li> </ul> </li> <?php } } ?> </ul> <input type="hidden" class="dgallery_ids" name="dgallery_ids" value="<?php if ($dgallery_ids) { echo esc_attr(implode(',', $dgallery_ids)); } ?> " /> <p class="add_dgallery_images hide-if-no-js"> <a href="#" data-choose="<?php _e('Add Images to Dynamic Gallery', 'woo_dgallery'); ?> " data-update="<?php _e('Add to gallery', 'woo_dgallery'); ?> " data-delete="<?php _e('Delete image', 'woo_dgallery'); ?> " data-text="<?php _e('Delete', 'woo_dgallery'); ?> "><?php _e('Add dynamic gallery images', 'woo_dgallery'); ?> </a> </p> </div> <?php // Add an nonce field so we can check for it later. wp_nonce_field('a3_dynamic_metabox_action', 'a3_dynamic_metabox_nonce_field'); ?> <div style="clear: both;"></div> </div> <div style="clear: both;"></div> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('input.actived_d_gallery').change(function() { if( jQuery(this).is(":checked") ) { <?php if ($wc_dgallery_hide_woo_gallery == 'yes') { ?> jQuery('#woocommerce-product-images').slideUp(); <?php } ?> } else { jQuery('#woocommerce-product-images').slideDown(); } }); }); </script> <?php $output = ob_get_clean(); echo $output; }
public static function wc_dynamic_gallery_display($product_id = 0) { /** * Single Product Image */ global $post, $wc_dgallery_fonts_face; $display_back_and_forward = 'true'; $no_image_uri = WC_Dynamic_Gallery_Functions::get_no_image_uri(); if ($product_id < 1) { $product_id = $post->ID; } // Get gallery of this product $dgallery_ids = WC_Dynamic_Gallery_Functions::get_gallery_ids($product_id); if (!is_array($dgallery_ids)) { $dgallery_ids = array(); } $main_dgallery = array(); $ogrinal_product_id = $product_id; $product_id .= '_' . rand(100, 10000); $lightbox_class = 'lightbox'; $thumbs_list_class = ''; if (count($dgallery_ids) > 0) { // Assign image data into main gallery array foreach ($dgallery_ids as $img_id) { // Check if image id is existed on main gallery then just use it again for decrease query if (isset($main_dgallery[$img_id])) { continue; } $image_data = get_post($img_id); $large_image_attribute = wp_get_attachment_image_src($img_id, 'large'); $thumb_image_attribute = wp_get_attachment_image_src($img_id, 'shop_thumbnail'); $alt = get_post_meta($img_id, '_wp_attachment_image_alt', true); $large_srcset = ''; $large_sizes = ''; $thumb_srcset = ''; $thumb_sizes = ''; if (function_exists('wp_get_attachment_image_srcset')) { $large_srcset = wp_get_attachment_image_srcset($img_id, 'large'); $thumb_srcset = wp_get_attachment_image_srcset($img_id, 'shop_thumbnail'); } if (function_exists('wp_get_attachment_image_sizes')) { $large_sizes = wp_get_attachment_image_sizes($img_id, 'large'); $thumb_sizes = wp_get_attachment_image_sizes($img_id, 'shop_thumbnail'); } $main_dgallery[$img_id] = array('caption_text' => $image_data->post_excerpt, 'alt_text' => $alt, 'thumb' => array('url' => $thumb_image_attribute[0], 'width' => $thumb_image_attribute[1], 'height' => $thumb_image_attribute[2], 'img_srcset' => $thumb_srcset, 'img_sizes' => $thumb_sizes), 'large' => array('url' => $large_image_attribute[0], 'width' => $large_image_attribute[1], 'height' => $large_image_attribute[2], 'img_srcset' => $large_srcset, 'img_sizes' => $large_sizes)); } } ?> <div class="images gallery_container"> <div class="product_gallery"> <?php $g_width = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_width_fixed') . 'px'; $shop_thumbnail = wc_get_image_size('shop_thumbnail'); $g_thumb_width = $shop_thumbnail['width']; $g_thumb_height = $shop_thumbnail['height']; $thumb_show_type = 'slider'; $thumb_columns = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'thumb_columns', 3); if ('static' == $thumb_show_type) { $thumbs_list_class = 'a3dg-thumbs-static'; } $g_auto = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_auto_start'); $g_speed = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_speed'); $g_effect = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_effect'); $g_animation_speed = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'product_gallery_animation_speed'); $popup_gallery = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'popup_gallery'); $hide_thumb_1image = get_option(WOO_DYNAMIC_GALLERY_PREFIX . 'hide_thumb_1image'); if ('static' == $thumb_show_type) { $display_back_and_forward = 'false'; } $zoom_label = __('ZOOM +', 'woo_dgallery'); if ('deactivate' == $popup_gallery) { $zoom_label = ''; $lightbox_class = ''; } $_upload_dir = wp_upload_dir(); if (file_exists($_upload_dir['basedir'] . '/sass/woo_dynamic_gallery.min.css')) { echo '<link media="all" type="text/css" href="' . str_replace(array('http:', 'https:'), '', $_upload_dir['baseurl']) . '/sass/woo_dynamic_gallery.min.css?ver=' . WOO_DYNAMIC_GALLERY_VERSION . '" rel="stylesheet" />' . "\n"; } else { include WOO_DYNAMIC_GALLERY_DIR . '/templates/customized_style.php'; } echo '<style>'; if ('yes' == $hide_thumb_1image && count($dgallery_ids) <= 1) { echo '#gallery_' . $product_id . ' .a3dg-nav{display:none;} .woocommerce #gallery_' . $product_id . ' .images { margin-bottom: 15px;}'; } echo ' </style>'; echo '<script type ="text/javascript"> jQuery(function() { var settings_defaults_' . $product_id . ' = { loader_image: "' . WOO_DYNAMIC_GALLERY_JS_URL . '/mygallery/loader.gif", start_at_index: 0, gallery_ID: "' . $product_id . '", lightbox_class: "' . $lightbox_class . '", description_wrapper: false, thumb_opacity: 0.5, animate_first_image: false, animation_speed: ' . $g_animation_speed . '000, width: false, height: false, display_next_and_prev: true, display_back_and_forward: ' . $display_back_and_forward . ', scroll_jump: 0, slideshow: { enable: true, autostart: ' . $g_auto . ', speed: ' . $g_speed . '000, start_label: "' . __('START SLIDESHOW', 'woo_dgallery') . '", stop_label: "' . __('STOP SLIDESHOW', 'woo_dgallery') . '", zoom_label: "' . $zoom_label . '", stop_on_scroll: true, countdown_prefix: "(", countdown_sufix: ")", onStart: false, onStop: false }, effect: "' . $g_effect . '", enable_keyboard_move: true, cycle: true, callbacks: { init: false, afterImageVisible: false, beforeImageVisible: false } }; jQuery("#gallery_' . $product_id . '").adGallery(settings_defaults_' . $product_id . '); }); </script>'; echo '<img style="width: 0px ! important; height: 0px ! important; display: none ! important; position: absolute;" src="' . WOO_DYNAMIC_GALLERY_IMAGES_URL . '/blank.gif">'; echo '<div id="gallery_' . $product_id . '" class="a3-dgallery" style="width: ' . $g_width . ';"> <div class="a3dg-image-wrapper"></div> <div class="a3dg-controls"> </div> <div class="a3dg-nav"> <div class="a3dg-thumbs ' . $thumbs_list_class . '"> <ul class="a3dg-thumb-list">'; $script_colorbox = ''; $script_fancybox = ''; if (count($dgallery_ids) > 0) { $script_colorbox .= '<script type="text/javascript">'; $script_fancybox .= '<script type="text/javascript">'; $script_colorbox .= '(function($){'; $script_fancybox .= '(function($){'; $script_colorbox .= '$(function(){'; $script_fancybox .= '$(function(){'; $script_colorbox .= '$(document).on("click", ".a3-dgallery .lightbox", function(ev) { if( $(this).attr("rel") == "gallery_' . $product_id . '") { var idx = $("#gallery_' . $product_id . ' .a3dg-image img").attr("idx");'; $script_fancybox .= '$(document).on("click", ".a3-dgallery .lightbox", function(ev) { if( $(this).attr("rel") == "gallery_' . $product_id . '") { var idx = $("#gallery_' . $product_id . ' .a3dg-image img").attr("idx");'; if (count($dgallery_ids) <= 1) { $script_colorbox .= '$(".gallery_product_' . $product_id . '").colorbox({open:true, maxWidth:"100%" });'; $script_fancybox .= '$.fancybox('; } else { $script_colorbox .= '$(".gallery_product_' . $product_id . '").colorbox({rel:"gallery_product_' . $product_id . '", maxWidth:"100%" }); $(".gallery_product_' . $product_id . '_"+idx).colorbox({open:true, maxWidth:"100%" });'; $script_fancybox .= '$.fancybox(['; } $common = ''; $idx = 0; foreach ($dgallery_ids as $img_id) { if (!isset($main_dgallery[$img_id])) { continue; } // Get image data from main gallery array $gallery_item = $main_dgallery[$img_id]; $li_class = ''; if ('static' == $thumb_show_type) { if ($idx % $thumb_columns == 0) { $li_class = 'first_item'; } elseif ($idx % $thumb_columns + 1 == $thumb_columns) { $li_class = 'last_item'; } } else { if ($idx == 0) { $li_class = 'first_item'; } elseif ($idx == count($dgallery_ids) - 1) { $li_class = 'last_item'; } } $image_large_url = $gallery_item['large']['url']; $image_thumb_url = $gallery_item['thumb']['url']; $thumb_height = $g_thumb_height; $thumb_width = $g_thumb_width; $width_old = $gallery_item['thumb']['width']; $height_old = $gallery_item['thumb']['height']; if ($width_old > $g_thumb_width || $height_old > $g_thumb_height) { if ($height_old > $g_thumb_height && $g_thumb_height > 0) { $factor = $height_old / $g_thumb_height; $thumb_height = $g_thumb_height; $thumb_width = $width_old / $factor; } if ($thumb_width > $g_thumb_width && $g_thumb_width > 0) { $factor = $width_old / $g_thumb_width; $thumb_height = $height_old / $factor; $thumb_width = $g_thumb_width; } elseif ($thumb_width == $g_thumb_width && $width_old > $g_thumb_width && $g_thumb_width > 0) { $factor = $width_old / $g_thumb_width; $thumb_height = $height_old / $factor; $thumb_width = $g_thumb_width; } } else { $thumb_height = $height_old; $thumb_width = $width_old; } echo '<li class="' . $li_class . '">'; echo '<a alt="' . esc_attr($gallery_item['alt_text']) . '" class="gallery_product_' . $product_id . ' gallery_product_' . $product_id . '_' . $idx . '" title="' . esc_attr($gallery_item['caption_text']) . '" rel="gallery_product_' . $product_id . '" href="' . $image_large_url . '">'; echo '<img org-width="' . esc_attr($gallery_item['large']['width']) . '" org-height="' . esc_attr($gallery_item['large']['height']) . '" org-sizes="' . esc_attr($gallery_item['large']['img_sizes']) . '" org-srcset="' . esc_attr($gallery_item['large']['img_srcset']) . '" sizes="' . esc_attr($gallery_item['thumb']['img_sizes']) . '" srcset="' . esc_attr($gallery_item['thumb']['img_srcset']) . '" idx="' . $idx . '" src="' . $image_thumb_url . '" alt="' . esc_attr($gallery_item['alt_text']) . '" data-caption="' . esc_attr($gallery_item['caption_text']) . '" class="image' . $idx . '" width="' . $thumb_width . '" height="' . $thumb_height . '">'; echo '</a>'; echo '</li>'; if ('' != trim($gallery_item['caption_text'])) { $script_fancybox .= $common . '{href:"' . $image_large_url . '",title:"' . esc_js($gallery_item['caption_text']) . '"}'; } else { $script_fancybox .= $common . '{href:"' . $image_large_url . '",title:""}'; } $common = ','; $idx++; } if (count($dgallery_ids) <= 1) { $script_fancybox .= ');'; } else { $script_fancybox .= '],{ \'index\': idx });'; } $script_colorbox .= 'ev.preventDefault();'; $script_colorbox .= '} });'; $script_fancybox .= '} });'; $script_colorbox .= '});'; $script_fancybox .= '});'; $script_colorbox .= '})(jQuery);'; $script_fancybox .= '})(jQuery);'; $script_colorbox .= '</script>'; $script_fancybox .= '</script>'; } else { echo '<li>'; echo '<a class="" rel="gallery_product_' . $product_id . '" href="' . $no_image_uri . '">'; echo '<img org-width="" org-height="" sizes="" srcset="" src="' . $no_image_uri . '" class="image" alt="">'; echo '</a>'; echo '</li>'; } if ('deactivate' == $popup_gallery) { $script_colorbox = ''; $script_fancybox = ''; } elseif ('colorbox' == $popup_gallery) { echo $script_colorbox; } else { echo $script_fancybox; } echo '</ul> </div> </div> </div>'; ?> </div> </div> <?php }