Skip to content

Instantly share code, notes, and snippets.

@kuokoad
Forked from mikejolley/functions.php
Created August 30, 2023 10:36
Show Gist options
  • Select an option

  • Save kuokoad/bff730762b7dbfebdb57f9b343332d0c to your computer and use it in GitHub Desktop.

Select an option

Save kuokoad/bff730762b7dbfebdb57f9b343332d0c to your computer and use it in GitHub Desktop.

Revisions

  1. @mikejolley mikejolley created this gist Jul 2, 2016.
    15 changes: 15 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    <?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;
    }
    }