1. Home
  2. Documentation
  3. WooCommerce Private Store
  4. Advanced Usage
  5. How to set the page template for the private store login page

How to set the page template for the private store login page

By default, WooCommerce Private Store uses the default page template in your theme when displaying the store login page (this is the page where users enter a password to unlock the store). The default page template is usually page.php.

At the present time, there’s no option or filter available to set a custom page template, but it can be achieved by adding a hook to template_include and checking the slug (i.e. post_name of the current page).

Here’s some example code which sets the template to page-store-login.php. For this code to work, the page-store-login.php file must exist in the current active theme (e.g. /wp-content/themes/my-theme/page-store-login.php).

// WooCommerce Private Store: set a custom template for the store login page.
add_filter( 'template_include', function( $template ) {
    global $post;

    if ( $post instanceof WP_Post && false !== strpos( $post->post_name, 'store-login' ) ) {
        // Change 'page-store-login.php' to the file name of your login page template, relative to your theme directory.
        $store_login_template = locate_template( 'page-store-login.php' );

        if ( $store_login_template ) {
            $template = $store_login_template;
        }
    }

    return $template;
} );

Was this article helpful?

Related Articles