Reputation: 49
I saw this link: Unset product tabs for specific product categories in woocommerce
I want to hide related product tabs for specific products.
I use this code:
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;
}
}
I used "unset( $tabs['related_products'] ); // (Related Products tab)" but there are the tab of related products for specific products.
Upvotes: 0
Views: 764
Reputation: 378
Try to add this code in your functions.php file:
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
Here is documentation of this: remove related products.
You can make condition for specific product IDs, and insert code above to condition.
Upvotes: 0
Reputation: 254373
In the code below, you will have to define an array of products where you want to hide the tab:
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;
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested on Woocommerce 3+ and works
Upvotes: 1