I'm trying to exclude some categories from being displayed on the WooCommerce product page.
Example: if in a single product page I have "Categories: Cat1, Cat"2", I want that only Cat1 will be displayed.
I tried editing the meta.php in the single-product template. I created a new function:
$categories = $product->get_category_ids();
$categoriesToRemove = array(53,76,77,78); // my ids to exclude
foreach ( $categoriesToRemove as $categoryKey => $category) {
if (($key = array_search($category, $categories)) !== false) {
unset($categories[$key]);
}
}
$categoriesNeeded = $categories;
Then I have the echo from WooCommerce:
echo wc_get_product_category_list( $product->get_id(), ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', count($categories), 'woocommerce' ) . ' ', '</span>' );
But it still shows the same categories. The strange thing is that when I do a var_dump($categories)
it shows the correct thing.