【问题标题】:Sorting products ASC from specific category in store woocommerceSorting products ASC from specific category in store woocommerce
【发布时间】:2022-12-01 23:02:11
【问题描述】:

im trying to sort asc by price a specific category for marketing purpouses. the thing is all the shop is configured to show desc, so i used a sn-p but its not working.

add_filter( 'woocommerce_product_query', 'sorting_asc_query', 10, 2 );
function sorting_asc_query( $q ) {
$product_category = array('category-to-be-sorted');
    if( is_product_category( $product_category ) ) {
        $q->set('orderby', 'post__in');
        $q->set('order', 'ASC');
    }
}

can you guide me to make it run?

cheers.

【问题讨论】:

  • Please be more specific - Are you wanting to order by product titles ascending alphabetically?
  • oooh sorry, by price. i will edit the question!

标签: woocommerce


【解决方案1】:

Give this a try - the default for the price variable is ascending. Be sure to replace uncategorized with your category slug.

add_filter( 'woocommerce_default_catalog_orderby', 'catalog_orderby_for_category' );

function catalog_orderby_for_category( $sort_by ) {
    if( is_product_category( 'uncategorized' ) ) { 
        return 'price';
    } else {
        return $sort_by;
    }
}

【讨论】:

    猜你喜欢
    • 2012-05-26
    • 2022-12-02
    • 2022-11-09
    • 2022-12-02
    • 2022-11-20
    • 1970-01-01
    • 2022-12-02
    • 2016-04-01
    • 2020-02-08
    相关资源
    最近更新 更多