How ещ redirect based on page in woocommerce?

by dalton_moen , in category: Third Party Scripts , a day ago

How ещ redirect based on page in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 8 hours ago

@dalton_moen 

To redirect based on the page in WooCommerce, you can use the following code in your theme's functions.php file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
add_action( 'template_redirect', 'custom_redirect_based_on_page');

function custom_redirect_based_on_page() {
    global $post;

    if( is_page( 'your-page-slug') ) { // Change 'your-page-slug' to the slug of the page you want to redirect from
        wp_redirect( 'http://example.com/new-page', 301 ); // Change 'http://example.com/new-page' to the URL of the page you want to redirect to
        exit();
    }
}


This code checks if the current page is the one you specified and then redirects the user to the new page URL you specified. Make sure to replace 'your-page-slug' and 'http://example.com/new-page' with the appropriate values for your site.