如果 WooCommerce 中的產品排序功能只是浪費空間,或者您根本不需要該功能,則可能需要透過 PHP 而不是 CSS 進行刪除。這只是一個更清潔的解決方案。這是您需要放在您的 functions.php 模板檔案中的程式碼。

目標:刪除 “預設排序”

片段:從商店和購物車頁面中刪除 “預設排序” 下拉選單

  // remove default sorting dropdown    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );    

刪除 StoreFront 主題中的 “預設排序” 下拉選單

  // remove default sorting dropdown in StoreFront Theme    add_action('init','delay_remove');    function delay_remove() {  remove_action( 'woocommerce_after_shop_loop', 'woocommerce_catalog_ordering', 10 );  remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 10 );  }    


可以在哪裡新增此程式碼?

您可以將 PHP 程式碼片段放置在主題或子主題的 functions.php 檔案的底部(如果是 CSS 程式碼,請新增到主題的 style.css 檔案底部),修改之前建議先備份原始檔案,若出現錯誤請先刪除此程式碼。


這段程式碼是否正常可用?

或者是您有更好的解決方案想要分享?請到薇曉朵 WooCommerce 中文論壇留言告知,我們希望可以幫到更多國內的 WooCommerce 使用者也希望您的參與。


需要關於 WooCommerce 的幫助?

請觀看我們提供的免費影片教程或到薇曉朵 WooCommerce 中文論壇提問,會有專業技術團隊提供相關幫助。