【问题标题】:How to exclude a variable price from the WooCommerce price filter?如何从 WooCommerce 价格过滤器中排除可变价格?
【发布时间】:2016-06-06 22:38:58
【问题描述】:

我需要从价格过滤器和 WooCommerce 订单中按价格删除一个特定的可变价格。

我有 4 个可变产品,我不想在价格过滤器中显示一个包含所有产品价格 $495 的可变属性。

我只是想隐藏这个特定属性,这样它就不会被计入价格过滤器以及按价格排序的 wordpress 中。

谢谢。

【问题讨论】:

    标签: php wordpress woocommerce product price


    【解决方案1】:

    你需要这样的东西:

    add_filter( 'woocommerce_sale_price_html',           'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_price_html',                'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_empty_price_html',          'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variable_sale_price_html',  'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variable_price_html',       'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variable_empty_price_html', 'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variation_sale_price_html', 'custom_remove_price_html', 20, 2 );
    add_filter( 'woocommerce_variation_price_html',      'custom_remove_price_html', 20, 2 );
    
    function custom_remove_price_html( $price, $product ) {
    
        // if this is a product is a variable product.
        if ( $product->is_type( 'variable' ) ) { // updated
            // $price = '';
            return;
        }
        return $price;
    }
    

    如果它不能按您的意愿工作,您需要微调函数内部的条件,以满足您的需求。

    您必须将此代码 sn-p 添加到您的活动主题(或更好的活动子主题)的 functions.php 文件中

    【讨论】:

    • 我有 4 个变量属性,我只需要删除一个并保留另一个 3. 我怎样才能获得属性的值,这样我就可以做一个 if 从数组中删除它?
    • 删除无变化 我有“许可类型”:网站、公司、行政和单身,我想从过滤器中删除行政价格
    猜你喜欢
    • 1970-01-01
    • 2020-06-03
    • 2020-12-10
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-12
    • 2017-11-24
    相关资源
    最近更新 更多