You will have to write a hook for that. I was going to suggest you just change that in Permalinks but if your site is older you might ruin your seo.
The easiest way is in permalinks but merchandise will have to change too.
If you know how to add a hook let me know.
I’d be happy to use a hook if you can give me a couple of pointers.
No I mean I was hoping you’d show me LOL I don’t know if it’s even possible. I mean anything’s possible. :o)
Seems like it should be pretty straightforward …
Just remove the action that builds the link url and add it back in with some logic to build the link for $category == membership with /product and leave the other links alone and using /product_category.
I just can’t figure out where the hook goes!
For the record, here’s what I have come up with in my search for a way to skip the product category page for a category with only 1 product:
This Woo function builds the url for the product category page inside the shop page loop:
function woocommerce_template_loop_category_link_open( $category ) {
echo '<a href="' . esc_url( get_term_link( $category, 'product_cat' ) ) . '">';
}
It can be removed with the woocommerce_before_subcategory hook. As in:
remove_action( 'woocommerce_before_subcategory',
'woocommerce_template_loop_category_link_open', 10 );
Then I created my own function to build the url. I took a bit of a shortcut since I know the ‘Membership’ category has only one product named ‘Membership’. If I was wanting to generalize this behaviour I would check the number of products in each category and build the product page url for any category with 1 product instead of the product category page url. Put that in my rainy day job jar 🙂
Here’s my brute force url builder:
function arcc_template_loop_category_link_open( $category ) {
$category_name = $category->name;
if ( $category_name == 'Membership' ) {
$product = get_page_by_title( 'Membership', OBJECT, 'product' );
$product_id = $product->ID;
$arcclink = get_the_permalink( $product_id );
} else {
$arcclink = get_term_link( $category, 'product_cat' );
}
echo '<a href="' . esc_url( $arcclink ) . '">';
}
add_action( 'woocommerce_before_subcategory',
'arcc_template_loop_category_link_open', 10);
I’m not sure what this does to the breadcrumbs but that’s for another day.
-
This reply was modified 7 years ago by
jwpalfa.