• Resolved foodstijl

    (@foodstijl)


    I creating a webshop and I don’t want users to go to the individual product pages. (I’ve set up en bulk shop page from where they can order everything).
    So I would like all urls (current and future) with /product/ to redirect to the shop page.
    I would think:
    /product/* >> shop url
    would work.
    But it didn’t..
    Anybody have any idea to accomplish this?

    Kind regards and best wishes,
    Emile

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • use (.*) instead of * and if that doesn’t work then you can use WordPress hook template_redirect to redirect the page on specific conditions but it required a bit of coding knowledge.

    Thread Starter foodstijl

    (@foodstijl)

    hi thanks for your quick reply.
    I’m afraid(.*) isn’t working.

    I’ll look into the WordPress hook template_redirect.
    thanks.

    Thread Starter foodstijl

    (@foodstijl)

    I’ve added the following function to function.php it works.

    add_action( 'wp', 'ts_redirect_product_pages', 99 );
     
    function ts_redirect_product_pages() {
         
        if ( is_product() ) {
            wp_safe_redirect( home_url('/shop/') );
            exit;
        } 
    }

    You can use better code to avoid Fatal errors on plugin deactivate by checking function exists also you can fetch dynamic page id from the WC settings

    /**
     * Redirect WC product page to main shop page.
     */
    function cusotm_wc_redirect_product_pages() {
    	if ( function_exists( 'is_product' ) ) {
    		if ( is_product() ) {
    			$shop_page_url = get_permalink( wc_get_page_id( 'shop' ) );
    			wp_safe_redirect( $shop_page_url );
    			exit;
    		}
    	}
    }
    add_action( 'template_redirect', 'cusotm_wc_redirect_product_pages', 99 );
    Plugin Support AR Rasel

    (@arrasel403)

    Hi @foodstijl,

    Sorry for the inconvenience caused.
    I have checked and it is working. You can check this screen record.

    Hope this will help you. Let us know how it goes.

    Thanks!

    Thread Starter foodstijl

    (@foodstijl)

    I see. thanks.
    I will use your code!

    • This reply was modified 2 years, 11 months ago by foodstijl.
    Plugin Support AR Rasel

    (@arrasel403)

    Hi @foodstijl,

    Hope you are doing well.
    Can you please inform me that is your above-mentioned issue already fixed or not?

    Let us know the update. Thanks!

    Plugin Support AR Rasel

    (@arrasel403)

    Hi @foodstijl,

    We haven’t heard back from you in a long time. So, I am assuming your issue has been resolved. I am closing this topic.

    Have a nice day!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘set bulk redirects’ is closed to new replies.