After declaring woocommerce theme support products are no longer displayed

The title basically says it all. I'm piecing through publishing my first theme and have copied the woocommerce template files right from the plugin. So they should be identical with no current changes. However, when I add theme support in functions.php I no longer have products displayed. The declaration is basically right from their github:

    function bad_billy_beards_add_woocommerce_support() {
    add_theme_support( 'woocommerce', array(
        'thumbnail_image_width' = 150,
        'single_image_width'    = 300,

        'product_grid'          = array(
            'default_rows'    = 3,
            'min_rows'        = 2,
            'max_rows'        = 8,
            'default_columns' = 4,
            'min_columns'     = 2,
            'max_columns'     = 5,
        ),
    ) );
}
add_action( 'after_setup_theme', 'bad_billy_beards_add_woocommerce_support' );

Thank you.

Topic woocommerce-offtopic php Wordpress

Category Web


I guess I kinda figured it out ... It would seem as I'm missing a bit here.

function bad_billy_beard_add_woocommerce_support() {
    add_theme_support( 'woocommerce', array(
        'thumbnail_image_width' => 150,
        'single_image_width'    => 300,

        'product_grid'          => array(
            'default_rows'    => 3,
            'min_rows'        => 2,
            'max_rows'        => 8,
            'default_columns' => 4,
            'min_columns'     => 2,
            'max_columns'     => 5,
        ),
    ) );
}
add_action( 'after_setup_theme', 'bad_billy_beard_add_woocommerce_support' );

remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

add_action('woocommerce_before_main_content', 'bad_billy_beard_start', 10);
add_action('woocommerce_after_main_content', 'bad_billy_beard_end', 10);

function bad_billy_beard_start() {
    echo '<section id="main">';
}

function bad_billy_beard_end() {
    echo '</section>';
}

See this post for WooCommerce templating mechanism. One basic principle is: only overwrite things that you want to customize, not more.

So you should remove all files that are not changed, look out for double lines of code(meaning you maybe declare the same things twice, maybe with different vars/namespace and/or something else), which might be the cause why it breaks.

For a custom product layout, I'd simply overwrite archive-products.php

Edit: You can use add_theme_support without the array at the end. Try that.

<?php
   function bad_billy_beards_add_woocommerce_support() {
       add_theme_support( 'woocommerce');
}
add_action( 'after_setup_theme', 'bad_billy_beards_add_woocommerce_support' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.