Answer the question
In order to leave comments, you need to log in
How to set a template for displaying products on the main WooCommerce?
Hello!
I want to display new and popular products on the main page. To do this, you can use shortcodes, you can use special functions. For example, the new release function:
if ( ! function_exists( 'storefront_recent_products' ) ) {
/**
* Display Recent Products
* Hooked into the `homepage` action in the homepage template
*
* @since 1.0.0
* @param array $args the product section args.
* return void
*/
function storefront_recent_products( $args ) {
if ( storefront_is_woocommerce_activated() ) {
$args = apply_filters( 'storefront_recent_products_args', array(
'limit' => 12,
'columns' => 4,
'title' => __ ( 'New In', 'storefront' ),
) );
$shortcode_content = storefront_do_shortcode( 'recent_products', apply_filters( 'storefront_recent_products_shortcode_args', array(
'per_page' => intval( $args['limit'] ),
'columns' => intval( $args['columns'] ),
) ) );
/**
* Only display the section if the shortcode returns products
*/
if ( false !== strpos( $shortcode_content, 'product' ) ) {
echo '';
do_action( 'storefront_homepage_before_recent_products' );
echo '' . wp_kses_post( $args['title'] ) . '';
do_action( 'storefront_homepage_after_recent_products_title' );
echo $shortcode_content;
echo '';
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question