小编Flo*_*ter的帖子

Woocommerce 按类别隐藏价格 + is_product_category()、is_shop()

你能帮我解决下面的代码吗?我需要隐藏特定类别的价格,但在商店和类别页面上,而不是在产品详细信息或管理上。

我需要添加is_product_category()is_shop()编码,但不知道具体在哪里。

该片段由jeroensormani.com提供

add_filter( 'woocommerce_get_price_html', function( $price, $product ) {
    if ( is_admin() ) return $price;

    // Hide for these category slugs / IDs
    $hide_for_categories = array( 'singles', 'albums' );

    // Don't show price when its in one of the categories
    if ( has_term( $hide_for_categories, 'product_cat', $product->get_id() ) ) {
        return '';
    }

    return $price; // Return original price
}, 10, 2 );

add_filter( 'woocommerce_cart_item_price', '__return_false' );
add_filter( 'woocommerce_cart_item_subtotal', '__return_false' );
Run Code Online (Sandbox Code Playgroud)

wordpress code-snippets woocommerce

2
推荐指数
1
解决办法
760
查看次数

标签 统计

code-snippets ×1

woocommerce ×1

wordpress ×1