隐藏Woocommerce

时间:2017-09-17 10:50:57

标签: php wordpress woocommerce product related-content

我看到了这个链接:Unset product tabs for specific product categories in woocommerce

我想隐藏特定产品的相关产品标签。

我使用此代码:

remove_action( 'woocommerce_after_single_product_summary', 'wpb_wrps_related_products',22 );
add_filter( 'woocommerce_product_tabs', 'wpb_wrps_adding_related_products_slider_to_product_tab' );
if( !function_exists('wpb_wrps_adding_related_products_slider_to_product_tab') ){
    function wpb_wrps_adding_related_products_slider_to_product_tab( $tabs ) {
        $tabs['wpb_wrps_related_products_slider'] = array(
            'title'       => __( 'Related Products','wpb-wrps' ),
            'priority'    => 30,
            'callback'    => 'wpb_wrps_related_products'
        );
        return $tabs;
    }
}

我使用了“未设置($ tabs ['related_products']); //(相关产品标签)”但是有特定产品的相关产品标签。

2 个答案:

答案 0 :(得分:1)

在下面的代码中,您必须定义要隐藏选项卡的产品数组:

remove_action( 'woocommerce_after_single_product_summary', 'wpb_wrps_related_products',22 );
add_filter( 'woocommerce_product_tabs', 'wpb_wrps_adding_related_products_slider_to_product_tab' );
if( !function_exists('wpb_wrps_adding_related_products_slider_to_product_tab') ){
    function wpb_wrps_adding_related_products_slider_to_product_tab( $tabs ) {
        global $product;

        // Define HERE the product IDs where you want to hide this custom tab
        $product_ids = array( 10, 15, 24, 98 );

        // If product match, we return normal tabs:
        if( in_array( $product->get_id(),  $product_ids ) ) return $tabs;

        // If product doesn't match, we add the custom tab:
        $tabs['wpb_wrps_related_products_slider'] = array(
            'title'       => __( 'Related Products','wpb-wrps' ),
            'priority'    => 30,
            'callback'    => 'wpb_wrps_related_products'
        );
        return $tabs;
    }
}

代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中。

此代码在Woocommerce 3+上测试并正常工作

答案 1 :(得分:0)

尝试在functions.php文件中添加此代码:          POST /books/_search?size=0 { "aggs": { "range": { "date_range": { "field": "BookCreated", "format": "yyyy-MM-dd", "ranges": [ { "from": "now-1M/M", "to": "now" } ] } } } }

以下是此文档:remove related products

您可以为特定产品ID创建条件,并将上面的代码插入条件。