Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Created July 2, 2016 13:21
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save mikejolley/b5c8e0b0dce07f615ccfb400604cfa87 to your computer and use it in GitHub Desktop.
Save mikejolley/b5c8e0b0dce07f615ccfb400604cfa87 to your computer and use it in GitHub Desktop.
WooCommerce - Redirect external products offsite (disable single listings)
<?php // Do not include this if already open!
/**
* Code goes in theme functions.php.
*/
add_action( 'template_redirect', 'redirect_external_products' );
function redirect_external_products() {
global $post;
if ( is_singular( 'product' ) && ! empty( $post ) && ( $product = wc_get_product( $post ) ) && $product->is_type( 'external' ) ) {
wp_redirect( $product->get_product_url() );
exit;
}
}
@rock977
Copy link

rock977 commented Apr 6, 2023

please help, it doesn't work for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment