如何在Storefront主题Woocommerce中添加额外的畅销产品?

时间:2018-05-03 11:13:52

标签: php wordpress woocommerce storefront

我是woocommerce的新人。如何在主页上将标准店面的最畅销部分从4x1扩展到4x4,16种产品?当我尝试mannualy更改storefront_best_selling_products函数时,没有什么不起作用。

2 个答案:

答案 0 :(得分:0)

在functions.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]');

希望这适合你。

答案 1 :(得分:0)

// "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;
}

将上述代码粘贴到子主题的functions.php的底部,并相应地更改“限制”和“列”的数量。

来源:Customize displayed products on Woocommerce Storefront home page