Allow homepage sections to be added/removed via filter

This commit is contained in:
Manos Psychogyiopoulos 2019-06-25 09:45:04 +03:00
parent 479da649ad
commit ae52fde6e6
3 changed files with 35 additions and 8 deletions

View file

@ -42,9 +42,9 @@ if ( storefront_is_woocommerce_activated() ) {
require 'inc/woocommerce/class-storefront-woocommerce-adjacent-products.php';
require 'inc/woocommerce/storefront-woocommerce-template-hooks.php';
require 'inc/woocommerce/storefront-woocommerce-template-functions.php';
require 'inc/woocommerce/storefront-woocommerce-functions.php';
require 'inc/woocommerce/storefront-woocommerce-template-functions.php';
require 'inc/woocommerce/storefront-woocommerce-template-hooks.php';
}
if ( is_admin() ) {

View file

@ -47,3 +47,32 @@ function storefront_get_next_product( $in_same_term = false, $excluded_terms = '
$product = new Storefront_WooCommerce_Adjacent_Products( $in_same_term, $excluded_terms, $taxonomy );
return $product->get_product();
}
/**
* Retrieves the homepage sections to diplay.
*
* @since 2.5.1
*
* @return array Array of homepage section to add.
*/
function storefront_get_homepage_sections() {
$sections = array(
20 => 'product_categories',
30 => 'recent_products',
40 => 'featured_products',
50 => 'popular_products',
60 => 'on_sale_products',
70 => 'best_selling_products'
);
/**
* Filter homepage sections.
*
* @since 2.5.1
*
* @param array $sections
*/
return apply_filters( 'woocommerce_storefront_homepage_sections', $sections );
}

View file

@ -8,6 +8,7 @@
/**
* Homepage
*
* @see storefront_get_homepage_sections()
* @see storefront_product_categories()
* @see storefront_recent_products()
* @see storefront_featured_products()
@ -15,12 +16,9 @@
* @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 );
foreach ( storefront_get_homepage_sections() as $priority => $section ) {
add_action( 'homepage', 'storefront_' . $section, $priority );
}
/**
* Layout