且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Woocommerce店面主页上自定义显示的产品

更新时间:2023-10-13 21:29:22

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.

相关阅读

推荐文章