WooCommerce 可以用來展示產品,只要開啓目錄模式 (Catalog Mode),即將與購買相關的內容去掉。本文介紹如何去掉價格和購買按鈕。

去掉價格字段

把代碼放在主題的 functions.php 下

//Hide price
add_filter( 'WooCommerce_get_price_html', 'WooCommerce_hide_price' );
function WooCommerce_hide_price( $price ){
    return '';
}

return 空字符串會隱藏價格,也可以選擇顯示一段文字。

去掉購買按鈕

//Hide buy button
add_action( 'init', 'WooCommerce_hide_buy_button' );
function WooCommerce_hide_buy_button(){
    remove_action( 'WooCommerce_after_shop_loop_item', 'WooCommerce_template_loop_add_to_cart', 10 );
    remove_action( 'WooCommerce_single_product_summary', 'WooCommerce_template_single_add_to_cart', 30 );
}

沒有購買按鈕,就無法向購物車中添加任何產品,購物車頁面可有可無。

如果完全不需要購物功能,將 WooCommerce 的購物車、結賬等頁面刪除即可。