Customize displayed products on Woocommerce Storefront home page

穿精又带淫゛_ 提交于 2019-12-30 10:59:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!