Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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( 
        array(
        '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">';
                the_post_thumbnail($large_thumbnail_size);
                echo '</a>';
            else :
                echo jigoshop_get_image_placeholder( 'shop_large' );
            endif;
//commented out this section so it wouldn't thumbnail ALL the products images, just one
            //do_action('jigoshop_product_thumbnails');

            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; ?>         
share|improve this answer
    
how about to redirect it to the cart page? –  loQ Oct 16 '13 at 13:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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