Jayson E Garcia
Jayson E Garcia

Reputation: 59

WordPress WooCommerce after theme setup not working

I just want to customize the theme of WooCommerce in my theme. But the problem is when I add the folder of WooCommerce template to override the WooCommerce theme and after adding this function:

function add_woocommerce_support() {
    add_theme_support( 'woocommerce' );
}
add_action( 'after_setup_theme', 'add_woocommerce_support' );

The shop page is not displaying the list of products. Instead the archive post is displaying. But when I comment the add_action of woocommerce theme setup, everything is working fine. See this picture:

enter image description here

I also have this function to display my custom post type all post in archive page:

function add_cpt_program_in_archive( $query ) {
    if ( !is_admin() && $query->is_archive() && $query->is_main_query() ) {
    $query->set( 'post_type', array('post', 'program' ) );
    }
}
add_action( 'pre_get_posts', 'add_cpt_program_in_archive' );

I also try to add !is_shop() in the condition of my add_cpt_program_in_archive function. So its look like this:

function add_cpt_program_in_archive( $query ) {
    if ( !is_admin() && $query->is_archive() && $query->is_main_query() && !is_shop() ) {
    $query->set( 'post_type', array('post', 'program' ) );
    }
}
add_action( 'pre_get_posts', 'add_cpt_program_in_archive' );

The shop page is now displaying the list of products. But the problem is when I visit the category page of product. Example the uncategorized category. It's not displaying the list of product that was in the uncategorized category. See this picture:

enter image description here

Upvotes: 0

Views: 181

Answers (1)

Jayson E Garcia
Jayson E Garcia

Reputation: 59

I found the solution. I add this code !$query->query_vars['product_cat']) in the condition of my add_cpt_program_in_archive function. So its look like this

function add_cpt_program_in_archive( $query ) {
    if ( !is_admin() && $query->is_archive() && $query->is_main_query() && !is_shop() && !$query->query_vars['product_cat']) {
    $query->set( 'post_type', array('post', 'program' ) );
    }
}
add_action( 'pre_get_posts', 'add_cpt_program_in_archive' );

But I dont know if this is correct format or maybe you guys have a better suggestion answer rather than to my solution.

Upvotes: 1

Related Questions