问题
I have been rattling my brain over this far too long and I cannot find the solution, I have attempted plugins, to the woo commerce documentation and the storefront documentation but no success.
The theme by default had a "New In" and "Best Sellers" where it listed 4 "New In" and 4 "Best Sellers"
I want to increase the 4 "New In" to 8 so 2 rows of 4 columns and update the "Best Sellers" to a Random so different products show
How can I achieve this?
Example: https://etzeo.com/
回答1:
The following will increase products from 4 to 8 (on four columns) for "New In" section and display "Best Sellers" to a random order on Storefront Home page:
// "New In" Home products section
add_filter( 'storefront_recent_products_args', 'filter_storefront_recent_products_args', 10, 1 );
function filter_storefront_recent_products_args( $args ) {
$args['limit'] = 8;
$args['columns'] = 4;
return $args;
}
// "Best Sellers" Home products section
add_filter( 'storefront_best_selling_products_args', 'filter_storefront_best_selling_products_args', 10, 1 );
function filter_storefront_best_selling_products_args( $args ) {
$args['orderby'] = 'rand'; // Random
return $args;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
来源:https://stackoverflow.com/questions/55012817/customize-displayed-products-on-woocommerce-storefront-home-page