【问题标题】:Hide related product tab for specific products in Woocommerce在 Woocommerce 中隐藏特定产品的相关产品选项卡
【发布时间】:2018-02-26 01:02:42
【问题描述】:

我看到了这个链接: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;
    }
}

我使用了“unset( $tabs['related_products'] ); // (Related Products tab)”,但是有特定产品的相关产品标签。

【问题讨论】:

    标签: php wordpress woocommerce product related-content


    【解决方案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+ 上经过测试并且可以正常工作

    【讨论】:

      【解决方案2】:

      尝试将此代码添加到您的functions.php文件中: remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );

      以下是相关文档:remove related products

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-23
        • 1970-01-01
        相关资源
        最近更新 更多