1 回答

TA貢獻(xiàn)1765條經(jīng)驗(yàn) 獲得超5個(gè)贊
隨著過濾鉤子,你需要總是返回第一個(gè)函數(shù)參數(shù)變量,而不僅僅是return 單純沒有價(jià)值或默認(rèn)函數(shù)變量參數(shù)...所以在你的代碼:
add_filter('woocommerce_default_catalog_orderby', 'custom_catalog_ordering_args', 10, 1);
function custom_catalog_ordering_args( $orderby )
{
$product_category = 'specials'; // <== HERE define your product category slug
// For all other archives pages
if ( ! is_product_category($product_category)) {
return $orderby; // <==== <==== <==== <==== <==== HERE
}
// For the defined product category archive page
return 'date';
}
或者這樣更好:
add_filter('woocommerce_default_catalog_orderby', 'custom_catalog_ordering_args', 10, 1);
function custom_catalog_ordering_args( $orderby ) {
// HERE define your product category slug
$product_category = 'specials';
// Only for the defined product category archive page
if ( is_product_category($product_category)) {
$orderby = 'date';
}
return $orderby;
}
現(xiàn)在應(yīng)該可以工作了。
- 1 回答
- 0 關(guān)注
- 423 瀏覽
添加回答
舉報(bào)