Need Help rewriting this code into a woocommerce function
-
I found this code;
<section id="recent"> <h1>Recently Added</h1> <ul class="row-fluid"> <?php $args = array( 'post_type' => 'product', 'stock' => 1, 'posts_per_page' => 4, 'orderby' =>'date','order' => 'DESC' ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?> <li class="span3"> <a id="id-<?php the_id(); ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="65px" height="115px" />'; ?> <h3><?php the_title(); ?></h3> <span class="price"><?php echo $product->get_price_html(); ?></span> </a> <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?> </li><!-- /span3 --> <?php endwhile; ?> <?php wp_reset_query(); ?> </ul><!-- /row-fluid --> </section><!-- /recent -->From here; http://wordpress.org/support/topic/display-woocommerce-recent-products-on-home-page?replies=12
But I need to put that code into a function.
The call to action is;
add_action( 'genesis_before_content', 'recent_products' );And the function that I need someone to help me rewrite to fit the above code is;
function recent_products() { echo '<div class="recent-products"><div class="wrap">'; genesis_widget_area( 'recent-products', array( 'before' => '<div class="recent-products">', 'after' => '</div>', ) ); echo '</div></div>'; }I need the code to still be wrapped in the div classes “recent-products” and “wrap.” I also need the add-action PHP to be left alone so it fits seamlessly in my theme.
I don’t know any PHP. Any help is appreciated!
The topic ‘Need Help rewriting this code into a woocommerce function’ is closed to new replies.