mirror of
https://github.com/woocommerce/storefront.git
synced 2025-08-20 04:00:29 +08:00
Move WC homepage sections
This commit is contained in:
parent
61f26bc5f3
commit
979e2868b1
4 changed files with 293 additions and 329 deletions
|
@ -544,321 +544,6 @@ if ( ! function_exists( 'storefront_posted_on' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_product_categories' ) ) {
|
||||
/**
|
||||
* Display Product Categories
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_product_categories( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_product_categories_args', array(
|
||||
'limit' => 3,
|
||||
'columns' => 3,
|
||||
'child_categories' => 0,
|
||||
'orderby' => 'name',
|
||||
'title' => __( 'Shop by Category', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'product_categories', apply_filters( 'storefront_product_categories_shortcode_args', array(
|
||||
'number' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'parent' => esc_attr( $args['child_categories'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns product categories
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product-category' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-product-categories" aria-label="' . esc_attr__( 'Product Categories', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_product_categories' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_product_categories_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_product_categories' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'title' => __( 'New In', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_recent_products_shortcode_args', array(
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'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 '<section class="storefront-product-section storefront-recent-products" aria-label="' . esc_attr__( 'Recent Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_recent_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_recent_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_recent_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_featured_products' ) ) {
|
||||
/**
|
||||
* Display Featured 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_featured_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_featured_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'visibility' => 'featured',
|
||||
'title' => __( 'We Recommend', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_featured_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'visibility' => esc_attr( $args['visibility'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-featured-products" aria-label="' . esc_attr__( 'Featured Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_featured_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_featured_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_featured_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_popular_products' ) ) {
|
||||
/**
|
||||
* Display Popular 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_popular_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_popular_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'rating',
|
||||
'order' => 'desc',
|
||||
'title' => __( 'Fan Favorites', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_popular_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-popular-products" aria-label="' . esc_attr__( 'Popular Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_popular_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_popular_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_popular_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_on_sale_products' ) ) {
|
||||
/**
|
||||
* Display On Sale Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @param array $args the product section args.
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_on_sale_products( $args ) {
|
||||
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_on_sale_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'on_sale' => 'true',
|
||||
'title' => __( 'On Sale', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_on_sale_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'on_sale' => esc_attr( $args['on_sale'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-on-sale-products" aria-label="' . esc_attr__( 'On Sale Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_on_sale_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_on_sale_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_on_sale_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_best_selling_products' ) ) {
|
||||
/**
|
||||
* Display Best Selling Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_best_selling_products( $args ) {
|
||||
if ( storefront_is_woocommerce_activated() ) {
|
||||
|
||||
$args = apply_filters( 'storefront_best_selling_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'popularity',
|
||||
'order' => 'desc',
|
||||
'title' => esc_attr__( 'Best Sellers', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_best_selling_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
|
||||
echo '<section class="storefront-product-section storefront-best-selling-products" aria-label="' . esc_attr__( 'Best Selling Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_best_selling_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products' );
|
||||
|
||||
echo '</section>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_homepage_content' ) ) {
|
||||
/**
|
||||
* Display homepage content
|
||||
|
|
|
@ -44,20 +44,8 @@ add_action( 'storefront_footer', 'storefront_credit', 20 );
|
|||
* Homepage
|
||||
*
|
||||
* @see storefront_homepage_content()
|
||||
* @see storefront_product_categories()
|
||||
* @see storefront_recent_products()
|
||||
* @see storefront_featured_products()
|
||||
* @see storefront_popular_products()
|
||||
* @see storefront_on_sale_products()
|
||||
* @see storefront_best_selling_products()
|
||||
*/
|
||||
add_action( 'homepage', 'storefront_homepage_content', 10 );
|
||||
add_action( 'homepage', 'storefront_product_categories', 20 );
|
||||
add_action( 'homepage', 'storefront_recent_products', 30 );
|
||||
add_action( 'homepage', 'storefront_featured_products', 40 );
|
||||
add_action( 'homepage', 'storefront_popular_products', 50 );
|
||||
add_action( 'homepage', 'storefront_on_sale_products', 60 );
|
||||
add_action( 'homepage', 'storefront_best_selling_products', 70 );
|
||||
|
||||
/**
|
||||
* Posts
|
||||
|
|
|
@ -237,6 +237,286 @@ if ( ! function_exists( 'storefront_woocommerce_pagination' ) ) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_product_categories' ) ) {
|
||||
/**
|
||||
* Display Product Categories
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_product_categories( $args ) {
|
||||
$args = apply_filters( 'storefront_product_categories_args', array(
|
||||
'limit' => 3,
|
||||
'columns' => 3,
|
||||
'child_categories' => 0,
|
||||
'orderby' => 'name',
|
||||
'title' => __( 'Shop by Category', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'product_categories', apply_filters( 'storefront_product_categories_shortcode_args', array(
|
||||
'number' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'parent' => esc_attr( $args['child_categories'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns product categories
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product-category' ) ) {
|
||||
echo '<section class="storefront-product-section storefront-product-categories" aria-label="' . esc_attr__( 'Product Categories', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_product_categories' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_product_categories_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_product_categories' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 ) {
|
||||
$args = apply_filters( 'storefront_recent_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'title' => __( 'New In', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_recent_products_shortcode_args', array(
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'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 '<section class="storefront-product-section storefront-recent-products" aria-label="' . esc_attr__( 'Recent Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_recent_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_recent_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_recent_products' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_featured_products' ) ) {
|
||||
/**
|
||||
* Display Featured 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_featured_products( $args ) {
|
||||
$args = apply_filters( 'storefront_featured_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'visibility' => 'featured',
|
||||
'title' => __( 'We Recommend', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_featured_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'visibility' => esc_attr( $args['visibility'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
echo '<section class="storefront-product-section storefront-featured-products" aria-label="' . esc_attr__( 'Featured Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_featured_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_featured_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_featured_products' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_popular_products' ) ) {
|
||||
/**
|
||||
* Display Popular 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_popular_products( $args ) {
|
||||
$args = apply_filters( 'storefront_popular_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'rating',
|
||||
'order' => 'desc',
|
||||
'title' => __( 'Fan Favorites', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_popular_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
echo '<section class="storefront-product-section storefront-popular-products" aria-label="' . esc_attr__( 'Popular Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_popular_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_popular_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_popular_products' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_on_sale_products' ) ) {
|
||||
/**
|
||||
* Display On Sale Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @param array $args the product section args.
|
||||
* @since 1.0.0
|
||||
* @return void
|
||||
*/
|
||||
function storefront_on_sale_products( $args ) {
|
||||
$args = apply_filters( 'storefront_on_sale_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'date',
|
||||
'order' => 'desc',
|
||||
'on_sale' => 'true',
|
||||
'title' => __( 'On Sale', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_on_sale_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
'on_sale' => esc_attr( $args['on_sale'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
echo '<section class="storefront-product-section storefront-on-sale-products" aria-label="' . esc_attr__( 'On Sale Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_on_sale_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_on_sale_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_on_sale_products' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_best_selling_products' ) ) {
|
||||
/**
|
||||
* Display Best Selling Products
|
||||
* Hooked into the `homepage` action in the homepage template
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param array $args the product section args.
|
||||
* @return void
|
||||
*/
|
||||
function storefront_best_selling_products( $args ) {
|
||||
$args = apply_filters( 'storefront_best_selling_products_args', array(
|
||||
'limit' => 4,
|
||||
'columns' => 4,
|
||||
'orderby' => 'popularity',
|
||||
'order' => 'desc',
|
||||
'title' => esc_attr__( 'Best Sellers', 'storefront' ),
|
||||
) );
|
||||
|
||||
$shortcode_content = storefront_do_shortcode( 'products', apply_filters( 'storefront_best_selling_products_shortcode_args', array(
|
||||
'per_page' => intval( $args['limit'] ),
|
||||
'columns' => intval( $args['columns'] ),
|
||||
'orderby' => esc_attr( $args['orderby'] ),
|
||||
'order' => esc_attr( $args['order'] ),
|
||||
) ) );
|
||||
|
||||
/**
|
||||
* Only display the section if the shortcode returns products
|
||||
*/
|
||||
if ( false !== strpos( $shortcode_content, 'product' ) ) {
|
||||
echo '<section class="storefront-product-section storefront-best-selling-products" aria-label="' . esc_attr__( 'Best Selling Products', 'storefront' ) . '">';
|
||||
|
||||
do_action( 'storefront_homepage_before_best_selling_products' );
|
||||
|
||||
echo '<h2 class="section-title">' . wp_kses_post( $args['title'] ) . '</h2>';
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products_title' );
|
||||
|
||||
echo $shortcode_content;
|
||||
|
||||
do_action( 'storefront_homepage_after_best_selling_products' );
|
||||
|
||||
echo '</section>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'storefront_promoted_products' ) ) {
|
||||
/**
|
||||
* Featured and On-Sale Products
|
||||
|
|
|
@ -6,10 +6,21 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Styles
|
||||
* Homepage
|
||||
*
|
||||
* @see storefront_woocommerce_scripts()
|
||||
* @see storefront_product_categories()
|
||||
* @see storefront_recent_products()
|
||||
* @see storefront_featured_products()
|
||||
* @see storefront_popular_products()
|
||||
* @see storefront_on_sale_products()
|
||||
* @see storefront_best_selling_products()
|
||||
*/
|
||||
add_action( 'homepage', 'storefront_product_categories', 20 );
|
||||
add_action( 'homepage', 'storefront_recent_products', 30 );
|
||||
add_action( 'homepage', 'storefront_featured_products', 40 );
|
||||
add_action( 'homepage', 'storefront_popular_products', 50 );
|
||||
add_action( 'homepage', 'storefront_on_sale_products', 60 );
|
||||
add_action( 'homepage', 'storefront_best_selling_products', 70 );
|
||||
|
||||
/**
|
||||
* Layout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue