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 的购物车、结账等页面删除即可。