Declaring support for WooCommerce

If you're developing a theme from scratch or if you're using a theme that wasn't designed to work with WooCommerce, you may see a notice on your site when you install WooCommerce. The following screenshot displays the theme-incompatibility message:

Declaring support for WooCommerce

This message can be easily dismissed by clicking on Hide this notice but, if you're planning on distributing this theme to others, then it's nice to let people know you designed your theme to work with WooCommerce.

Getting ready

You'll need to install a theme that shows the notice shown in the preceding screenshot. If your theme doesn't show this notice, then it's already declared support for WooCommerce and you can skip this recipe.

If you're a theme developer, you may have heard of Underscores. This starter theme hasn't declared support for WooCommerce, so if you base your theme on Underscores, you'll need to declare support. See the Underscores website for more information at http://underscores.me/.

How to do it…

Declaring that your theme supports WooCommerce takes a pretty small code snippet. We'll add that code snippet to your theme's functions.php file and then we'll be done. In the following steps, we declare support for our WooCommerce theme:

  1. Open up your theme's functions.php file in your code editor.
  2. Add the following code to the bottom of your functions.php file:
    add_action( 'after_setup_theme', 'woocommerce_coobook_support' ); 
    function woocommerce_coobook_support() { 
        add_theme_support( 'woocommerce' ); 
    }
  3. Save and upload the file.

How it works…

It's worth noting that adding this code only hides the notice. It doesn't automatically make your theme work with WooCommerce. You should go through all of the WooCommerce pages and make sure that everything looks correct.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset