0

I need to remove some discontinued products from a woocommerce site. I'm just wondering how to go about automating this. I haven't figured out whether to throw a 301, 404 or 410 error, but either way, is there an easy way to automate this for future removed products?

Your help is appreciated.

  • Found this plugin, but it's not updated. But if you can manage manual process, I found Redirection plugin a good one for redirection. I tried something like this, but you can see, it's not working. – Mayeenul Islam Dec 3 '15 at 4:45
0

You can actually use PHP to make redirects, rather than just .htaccess, which has the benefit of allowing you to use variables.

I don't really know woocommerce too well but you could create a redirect similar to this.

Note this is pseudo code. These function calls are fictional but the logic will still apply

function redirect_product() {

    $product_status = get_product(); 

    $product_url = get_product_url();  

    if ($product_status === NULL) {

       $URL = $_SERVER['REQUEST_URI'];
       if ( $URL == $product_url) {
         header( 'HTTP/1.0 301 Moved Permanently' );
         header( 'Location: /' ); //redirect to url of your choosing
         exit();
       } else {
         return;
       }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.