I am using Jigoshop to build an e-commerce site.

The end goal is for the front page to have a featured products section.

Jigoshop provides a shortcode, but the shortcode defaults to the medium image size. I would like to use the large image size, and so I did a WP_query conditionally to check for featured images, grabbed the image, product title and description, but can't seem to figure out how to get the "add to cart" button generated.

Any ideas?


Okay, I managed to figure it out (after far too many hours...):

Here is the code, feel free to let me know if it's ugly, as I'm new to both wordpress and php:

//Query the wordpress database for product posts
  $my_products = new WP_Query( 
        'post_type' => 'product',
//loop through my queried posts
<?php while ($my_products->have_posts()) : $my_products->the_post(); $_product = &new jigoshop_product( $post->ID );?>     
//find the posts that have the meta_key 'featured' with the value of 'yes' (they all have a featured tag with either yes or no)
        <?php if(get_post_meta($post->ID, 'featured', yes) == 'yes') : ?>
//make the product header a link to the product page
        <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>

//copied this code for getting the product thumbs                 
        <?php echo '<div class="images">';

            $thumb_id = 0;
            if (has_post_thumbnail()) :
                $thumb_id = get_post_thumbnail_id();
                // since there are now user settings for sizes, shouldn't need filters -JAP-
                //$large_thumbnail_size = apply_filters('single_product_large_thumbnail_size', 'shop_large');
                $large_thumbnail_size = jigoshop_get_image_size( 'shop_large' );
//had to edit the href from original value to .get_permalink so it would link to product page instead of the image itself
                echo '<a href="'.get_permalink().'" rel="thumbnails">';
                echo '</a>';
            else :
                echo jigoshop_get_image_placeholder( 'shop_large' );
//commented out this section so it wouldn't thumbnail ALL the products images, just one

            echo '</div>'; ?>

//get the product description        
        <p><?php the_content(); ?></p>

//create the 'add to cart' button
        <a href="<?php echo $_product->add_to_cart_url(); ?>" class="button"><?php _e('Add to cart', 'jigoshop'); ?></a> 

//reset the query (no idea if this is necessary, anyone?
    <?php wp_reset_query(); ?>
<?php endif; ?>
 <?php endwhile; ?>         
  • how about to redirect it to the cart page? – loQ Oct 16 '13 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.