我是 woocommerce的新手。如何将标准店面最畅销的部分从 4x1 扩展到 4x4,主页上有 16 种产品?当我尝试手动更改storefront_best_selling_products功能时,没有什么不起作用。
在函数中添加以下代码.php:
function storefront_best_selling_products( $args ) {
if ( storefront_is_woocommerce_activated() ) {
$args = apply_filters( ‘storefront_best_selling_products_args’, array(
‘limit’ => 5,
‘columns’ => 5,
‘title’ => esc_attr__( ‘Best Sellers’, ‘storefront’ ),
) );
echo ‘<section class=”storefront-product-section storefront-best-selling-products” aria-label=”Best Selling Products”>’;
do_action( ‘storefront_homepage_before_best_selling_products’ );
do_action( ‘storefront_homepage_after_best_selling_products_title’ );
echo storefront_do_shortcode( ‘best_selling_products’, array(
‘per_page’ => intval( $args[‘limit’] ),
‘columns’ => intval( $args[‘columns’] ),
) );
do_action( ‘storefront_homepage_after_best_selling_products’ );
echo ‘</section>’;
}
}
简码
add_shortcode( ‘best_sellers’, ‘storefront_best_selling_products’ );
像这样使用"best_sellers"短代码
do_shortcode('[best_sellers]');
希望这对你有用。
// "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
$args['limit'] = 16; // Quantity in total
$args['columns'] = 4;
return $args;
}
将上面的代码粘贴到子主题函数的底部.php并相应地更改"限制"和"列"的数量。
来源:自定义Woocommerce店面主页上显示的产品