The right way to add woocommerce to any wordpress theme, add woocommerce to custom theme easily, add woocommerce support to twentyfifteen theme.

How To Add WooCommerce To WordPress Theme

Just 3 steps:

  1. Install WooCommerce plugin.
  2. Add some functions to “functions.php” file.
  3. Make new file “woocommerce.php” inside your theme folder.

Step 1

Download WooCommerce plugin, install it and activate it.

Step 2

Copy this code and paste it in your “functions.php” file:


function twentyfifteen_woocommerce_support(){
/* By Qassim Hassan, https://wp-time.com */
add_theme_support( 'woocommerce' ); // WooCommerce support
}
add_action('after_setup_theme', 'twentyfifteen_woocommerce_support');

// WooCommerce remove actions
remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

Step 3

Make file “woocommerce.php”:

Duplicate “page.php” file of your theme, if your theme no has “page.php” file, don’t worry, duplicate “index.php” file, anyway change file name to “woocommerce.php”, now find this line and remove it:


while ( have_posts() ) : the_post();

Now find this line and remove it:


endwhile;

Now find this line:


get_template_part( 'content', get_post_format() );

Replace it to:


<?php woocommerce_content(); ?>

If your theme no has get_template_part() function, replace this line:


the_content();

Example

For example “twentyfifteen” theme, page.php file before the change:


get_header(); ?>

<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<?php
// Start the loop.
while ( have_posts() ) : the_post();

// Include the page content template.
get_template_part( 'content', 'page' );

// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;

// End the loop.
endwhile;
?>

</main><!-- .site-main -->
</div><!-- .content-area -->

<?php get_footer(); ?>

And page.php file after the change:


<?php

get_header(); ?>

<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">

<article id="post-<?php the_ID(); ?>" <?php post_class('hentry'); ?>>
<?php
// Post thumbnail.
twentyfifteen_post_thumbnail();
?>

<header class="entry-header">
<?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->

<div class="entry-content">
<?php woocommerce_content(); ?>
</div><!-- .entry-content -->

<?php edit_post_link( __( 'Edit', 'twentyfifteen' ), '<footer class="entry-footer"><span class="edit-link">', '</span></footer><!-- .entry-footer -->' ); ?>

</article><!-- #post-## -->

</main><!-- .site-main -->
</div><!-- .content-area -->

<?php get_footer(); ?>

Now copy previous code and paste it in “woocommerce.php” file, and add “woocommerce.php” file inside theme folder.

Add WooCommerce To Twenty Fifteen Theme Easily

Download this file, unzip it, now copy “woocommerce.php” file and paste it inside “twentyfifteen” theme folder, now your twentyfifteen theme is support WooCommerce! Don’t forget step number 2.

For more info, read this, enjoy.