WooCommerce: Change Product Permalinks @ Shop / Loop Pages

A BloomerArmada fan asked me a very interesting question: how can I link each product in the shop page to its own custom landing page as opposed to the default permalink?

Of course this applies when you don’t want to use the default single product page for all or some products. Clearly, you could set up a 301 redirect from the single product page to the landing page – that will help for SEO as well. But if this is temporary, or you need to still give access to the single product page later on, then a redirect is no good.

So, here’s how you can override the default permalink.

Linking a product to a custom landing page URL instead of the default WooCommerce single product permalink

PHP Snippet: Change Product Links @ WooCommerce Shop / Loop Pages

Thankfully, the woocommerce_template_loop_product_link_open() function, which is responsible for the product “a href” in the loop pages, contains a filter called woocommerce_loop_product_link

You can therefore change that link with add_filter() and return your custom URL instead of the default permalink.

It even gives you access to $product, which means if you have the custom URL saved in a custom field, you can return that programmatically.

/**
* @snippet       Change Product Permalinks @ WooCommerce Shop
* @how-to        Get CustomizeWoo.com FREE
* @author        Rodolfo Melogli
* @compatible    WooCommerce 4.0
* @donate $9     https://businessbloomer.com/bloomer-armada/
*/

add_filter( 'woocommerce_loop_product_link', 'bbloomer_change_product_permalink_shop', 99, 2 );

function bbloomer_change_product_permalink_shop( $link, $product ) {
   $this_product_id = $product->get_id();
   // E.G. CHANGE LINK FOR PRODUCT ID = 25
   if ( $this_product_id === 25 ) $link = '/custom-landing-page';
   return $link;
}

Where to add this snippet?

You can place PHP snippets at the bottom of your child theme functions.php file (delete "?>" if you have it there). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my free video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.3.

If you think this code saved you time & money, feel free to join 14,000+ WooCommerce Weekly subscribers for blog post updates or 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

32 thoughts on “WooCommerce: Change Product Permalinks @ Shop / Loop Pages

  1. There was a posibility to modify also the target type? We are changing the link, but, I would like to set its target as “_blank”.

    This is possible?

    Thanks, for sharing! 🙂

    1. Hello Ferran, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi,
    Thanks for the snippet, but the permalinks linked to the product title is not getting changed, any means to change that too?

    Thanks

    1. Hi Sam, are you on a custom / non default theme?

  3. Hello everyone!

    I hope you can help me. Unfortunately, I am very new to coding, but I want to find a solution to a problem.

    I would like some products to be loaded with a landing page instead of the “traditional woocommerce” product page. I used the code mentioned above and I was very happy (thank you very much again !!!) because it works.

    There is a tiny problem (this is an interesting phenomenon for me). On the product category pages, if I click on the product name, it will load the “traditional woocommerce product page”, and if I click on the image, it will load the landing page set by the code mentioned above. 🙁 I would like the mentioned landing page to load even if I click on the product name for each product. Maybe I need to add a detail to the mentioned code. Could someone help? I would be very grateful!

    Theme I use: Astra
    Page builder: Gutenberg + UAG

    Thank you very much in advance!

    1. Is the product name linking to the exact URL you set up in the redirect?

  4. first thank you for this tutorial

    my problem is i tried this code but it is not working with my theme because when i deactivatedthe theme it is work fine
    but i can’t change my theme so i don’t know what to do can you help me please

    thank you

    1. Hi Achraf, thanks so much for your comment! Yes, this is definitely fixable, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  5. Would this still work for a product category as well?

    1. Nope, need a different snippet for that

  6. Hi Rodolfo,

    Thanks for this article, this solution works only when you render the products on the first page.

    As soon as you move on to clicking on pagination links – 2, 3 ,4 etc., the product loop filter no longer works. Is there a separate filter I should be considering for products rendered via ajax calls.

    Many thanks for your help.

    1. That’s not possible, there must be a bug. Try switching to 2020 and disable all plugins but Woo, then test again

  7. Do you have a similar solution for the “add to cart” button? I would like to specify where the button leads to for each product. Thanks.

    1. Hi Ken, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  8. Thank you Rudolfo! Is it possible to change the checkout permalink of only one product?

    1. Yes! I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know 🙂

  9. thank u so much Mr.Rodolfo , your code is clean and simple , my problem solve now .

    1. Nice!

  10. Hello Rodolfo,

    I have tried to apply the code as per your instruction given to Surguci with Twentyseventeen hteme and all plugins disabled except WooCommerce (my current version is 4.0.1) and WordPress 5.3.2 and it does not work. Can you give me instructions on what is happening?

    Thanks,
    Venahat

    1. Try removing the .com from the URL. Also, can you paste here the snippet you used?

  11. Hello Rudolfo,

    I found your very helpfull Snippet. But I have some trouble with it – because it doesn’t work. I use the Lahanna Template. And I created a page with a block. At this block I placed a woocommerce-widget to show products from only one brand. But I need to change the link to our “main shop” at an other Domain. I have a page with all products from all brands and so on and here I changed the function “woocommerce_before_shop_loop_item” and it works propper….
    But on my “Brand-Page” your Snippet won’t run. And I’m wondering why 🙂
    Is a widget placed on a WordPress-Page still a Woocommerce Thang, or is it a Word-Press-Thang. And I need to customice a WordPress-Link-Template?
    I hope you can understand, what I’m asking for – and you can give me some advisr or tips, how I can solve my problem.

    THank you very much, for your support.

    1. Hello Jorg, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  12. Rodolfo you’re the man! Great tip as always!
    I wonder if it’s possible to make all product links point back to their sub category and not the product page?

    Let’s say we have this:

    Category: cars
    Sub category: blue_cars
    Product: blue_car

    I would like this link:
    mysite.com/index.php/product/blue-car/
    to point to:
    mysite.com/index.php/product-category/cars/blue-cars/

    Can it be done with one little snippet instead of creating many different variations of this snippet?

    Many thanks!

    1. Hello Teddy, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  13. Hi Rodolfo,

    Read your post on 21+ SEO optimization tips for WooCommerce and this post really is the core of an issue I am facing.

    My family business is a cosmetics site and is small scale so no real budget for hefty development.

    So I am pretty savvy with WordPress development but am weak on SEO.

    I want to create a unique and customised product page for each product to give a unique experience for each one. I am using the WooCommerce product page shortcodes which gives me greater flexibility on the page layout. However, if I use a 301 from the original product to the new design, will I trash my SEO?

    I also considering just swapping the permalink structure and sliding the new custom pages in place of the old original WooCommerce product pages. Then a noindex on the default content as it would display on the custom pages and I want to avoid duplicates

    However would you recommend the suggestion in this post above the ideas I added above?

    Any guidance would be appreciated. Thanks

    1. Hi there – ideally the best would be to keep using your original product pages, and customize them (example: https://businessbloomer.com/customize-single-product-page/). Otherwise, a 301 redirect is no problem either – it really depends on how much you need to customize product pages

  14. Hello,
    the code is not working anymore on the latest wordpress and woocommerce version.
    Can you take a look and test again?
    Regards

    1. It should work – are you linking to the same website, right?

      To troubleshoot, disable all plugins but WooCommerce and also switch temporarily to “Twentyseventeen” theme (load the snippet there in functions.php) – does it work? If yes, you have a problem with your current theme or one of the plugins.

      Hope this helps!

      R

  15. hello and thank you for this?
    can do it with redirect plugin easily, any diffrence between redirect trough and your sulution?
    thank you

    1. Hey Saeed, thanks for your comment! No difference, no – but for a few redirects it may be easy to keep them all together into a single snippet 🙂

  16. Hey! Appreciate you creating this tutorial for me Rodolfo 🙂

    1. 🙂

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between shortcodes: [php]code_here[/php]. Failure to complying with this (as well as going off topic, not writing in English, etc.) will result in comment deletion. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining BloomerArmada to get blog comment reply priority, ask me 1-to-1 WooCommerce questions and enjoy many more perks. Thank you :)

Your email address will not be published.