WordPress: Multiple Image on WP-Ecommerce Product Pages

WP-Ecommerce is an easy to use e-commerce plugin for WordPress. It has a vast range of features for a free plugin, but there are limits the developer imposes to encourage you to buy their premium add-on, “Gold Cart”. One thing that annoyed me in particular was the inability to have multiple product images on a product page, a feature only included within the Gold Cart add-on. I found a way around this by doing the following…

Find this code in wpsc-single_product.php:

<?php if ( wpsc_the_product_thumbnail() ) : ?>
	<a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo wpsc_the_product_image(); ?>">
		<img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(get_option('product_image_width'),get_option('product_image_height'),'','single'); ?>"/>
	</a>
	<?php 
	if ( function_exists( 'gold_shpcrt_display_gallery' ) )
		echo gold_shpcrt_display_gallery( wpsc_the_product_id() );
	?>
<?php else: ?>

and replace it with this:

<?php if ( wpsc_the_product_thumbnail()) : //if the product has any images...
      if (has_post_thumbnail()): //...display the thumbnail if there is one...?>
         <a rel="lightbox&#91;<?php echo wpsc_the_product_title(); ?>]" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo wpsc_the_product_image(); ?>">
         <?php echo get_the_post_thumbnail(wpsc_the_product_id(),'thumbnail',array('alt' => wpsc_the_product_title(),'title' => wpsc_the_product_title() ));?>
         </a>
      <?php endif;
      caz_get_images_for_product(wpsc_the_product_id());//...and then display all the rest of the images
else: ?>

I used the standard WordPress function, get_the_post_thumbnail() instead of the WP-Ecommerce function wpsc_the_product_thumbnail() to ensure a consistent display of thumbnails. So basically, I am displaying the product thumbnail and then using a custom function caz_get_images_for_product() to retrieve any other images associated with that product. This function effectively replaces the gold_shpcrt_display_gallery() function.

Now all you need to do is include the function within your templates functions.php file as below:

function caz_get_images_for_product($id){
global $wpdb;
$post_thumbnail = get_post_thumbnail_id();//read the thumbnail id
$attachments = $wpdb->get_results($wpdb->prepare(“SELECT * FROM $wpdb->posts WHERE post_parent = $id AND post_type = ‘attachment’ ORDER BY menu_order ASC”,$id));
foreach ($attachments as $attachment){
if ($attachment->ID <> $post_thumbnail){//if we haven’t already got the attachment as the post thumbnail
$image_attributes = wp_get_attachment_image_src($attachment->ID,’thumbnail’);?>
” alt=”“/>

Free Graphics, Icons, Tutorials
Free Graphics Free Christmas Vector Icon Graphics Pack 2017Free Fitness Vector Icons Graphics PackFree Camping Vector Graphics PackFree Summer Graphics PackFree File Icon PackFree Fast Food Vector Graphics
Sharing is caring...
Like & Follow
Share the love, share this page! Facebook Twitter Google Digg Reddit LinkedIn Pinterest Email
Close [X]
The Web Taylor
1000 Lakeside North Harbour Portsmouth, Hampshire PO6 3EN
02392 123358