This topic has 15 replies, 3 voices, and was last updated 4 years ago ago by Olga Barlow
hallo,
1. we have problem with you saw recently , link at private
2. we need at “Το Lα Ρelle προτείνει” that is related products to see only products from same category at the first raw and at the second raw all the products at same gender
1. we have problem with” saw recently” in article**
The cache plugin is the wprocket, but creates problem to “saw recently”
Hello,
1) Describe the problem in more detail with a screenshot.
2) WooCommerce does not have the option to set the related products from Dashboard, it takes them automatically by category or tag – https://docs.woocommerce.com/document/related-products-up-sells-and-cross-sells/
Regards
Add this to your functions.php or custom plugin.
function exclude_brands_from_related( $categories ){
// array of category id's that should be excluded
$exclude_cats = array( '100', '101', '102');
foreach( $categories as $index => $cat ){
if( in_array( $cat->term_id, $exclude_cats ) ){
unset($categories[$index]);
}
}
return $categories;
}
add_filter( 'woocommerce_get_related_product_cat_terms', 'exclude_brands_from_related' );
its will work something like this?
Hello,
1) Describe the issue with the Recently viewed products in more detail.
2) Read this post https://wordpress.org/support/topic/exclude-categories-from-related-products/
Regards
we want to exclude the categories id ‘103’, ‘102’, ‘105’, ‘100’, ‘105’, ’94’, ‘227’
but the code is not ok:
add_filter( ‘woocommerce_get_related_product_cat_terms’, ‘exclude_brands_from_related’ );
function exclude_brands_from_related( $categories ){
// array of category id’s that should be excluded
$exclude_cats = array( ‘103’, ‘102’, ‘105’, ‘100’, ‘105’, ’94’, ‘227’);
foreach( $categories as $index => $cat ){
if( in_array( $cat, $exclude_cats ) ){
unset($categories[$index]);
}
}
return $categories;
}
add_filter( ‘woocommerce_get_related_product_cat_terms’, ‘exclude_brands_from_related’ );
Hello,
Try this one
add_filter( 'woocommerce_get_related_product_cat_terms', 'exclude_brands_from_related', 20, 1 );
function exclude_brands_from_related( $categories ){
// array of category id's that should be excluded
$exclude_cats = array( '103', '102', '105', '100', '105', '94', '227');
$categories = array_diff($categories, $exclude_cats);
return $categories;
}
Regards
we cant make it work, our functions.php now:
<?php
defined( 'ABSPATH' ) || exit( 'Direct script access denied.' );
/*
* Load theme setup
* ******************************************************************* */
require_once( get_template_directory() . '/theme/theme-setup.php' );
/*
* Load framework
* ******************************************************************* */
require_once( get_template_directory() . '/framework/init.php' );
/*
* Load theme
* ******************************************************************* */
require_once( get_template_directory() . '/theme/init.php' );
add_filter( 'woocommerce_get_related_product_cat_terms', 'exclude_brands_from_related', 20, 1 );
function exclude_brands_from_related( $categories ){
// array of category id's that should be excluded
$exclude_cats = array( '103', '102', '105', '100', '105', '94', '227');
$categories = array_diff($categories, $exclude_cats);
return $categories;
}
Hello,
1) Did you add the code to parent theme functions.php? Don’t make any changes to the parent theme! Use child theme to make changes.
2) If the code still does not work then submit customization request here, please. Because we are unable to provide support for customizations under our Support Policy.
Regards
we havent a child theme
Hello,
I have installed child theme for you. Move all the changes you made in parent theme to child theme https://developer.wordpress.org/themes/advanced-topics/child-themes/
In other case you will lose them after theme update.
Regards
even at child theme the problem still there
$exclude_cats = array( ‘103’, ‘102’, ‘105’, ‘100’, ‘105’, ’94’, ‘227’);
here is our woocomrce category id
Hello,
Submit customization request here, please. Because we are unable to provide support for customizations under our Support Policy.
Regards
you give us a code before. its not possible to make it work..
Hello,
Provide us with WP Dashboard and FTP access to your site. We’ll check your problem on an exceptional basis but if you need any other additional customization contact the customization team.
Regards
You must be logged in to reply to this topic.Log in/Sign up