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 would like some help with the following issue with woocommerce.

I am using wordpress 3.5.2, woocommerce 2.0.13 and sommerce theme.

I have a product category page, in which I display 5 subcategories. Under the 5 subcategory images, I would like to have some featured products or random products of these categories. Do you know how I could do that?

share|improve this question
    
woocommerce has some widgets that can do the trick. Just check it. –  JMau Jul 26 '13 at 18:53

1 Answer 1

I just double checked and WooCommerce runs the product category description through the_content filters, which means that it should run shortcodes.

WooCommerce has plenty of shortcodes, see their documentation

Including featured products:

[featured_products per_page="12" columns="4"]

The downside to that is that the featured products might not all be from that specific category. You didn't mention if that was an issue or not.

If so, then you can duplicate the code from the [featured_products] (which is really just running a secondary loop with WP_Query), tweak it a bit and add the output to the woocommerce_before_shop_loop hook.

function wpa_107952_featured (){

    if( !is_product_category() )
        return;


    $args = array(
        'post_type' => 'product',
        'product_cat' => get_query_var('product_cat'),
        'post_status' => 'publish',
        'ignore_sticky_posts'   => 1,
        'posts_per_page' => 8,
        'meta_query' => array(
            array(
                'key' => '_visibility',
                'value' => array('catalog', 'visible'),
                'compare' => 'IN'
            ),
            array(
                'key' => '_featured',
                'value' => 'yes'
            )
        )
    );

    ob_start();

    $products = new WP_Query( $args );

    $woocommerce_loop['columns'] = 4;

    if ( $products->have_posts() ) : ?>

        <?php woocommerce_product_loop_start(); ?>

            <?php while ( $products->have_posts() ) : $products->the_post(); ?>

                <?php woocommerce_get_template_part( 'content', 'product' ); ?>

            <?php endwhile; // end of the loop. ?>

        <?php woocommerce_product_loop_end(); ?>

    <?php endif;

    wp_reset_postdata();

    echo '<div class="woocommerce">' . ob_get_clean() . '</div>';
}

add_action( 'woocommerce_before_shop_loop', 'wpa_107952_featured' );
share|improve this answer

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.