Woocommerce different template for products

I want to set different template for the relevant product category. I changed single-product.php file

   if (is_product_category( 'first-category' )) {
    woocommerce_get_template_part( 'content', 'single-product' );
}else{
    woocommerce_get_template_part( 'content', 'single-product-other' );
}

Still is loading content-single-product-other.php file content. I’m sure that the category of the product is checked

Related posts

2 comments

  1. it can happen if you have putted single-product-other.php in (yourtheme/woocommerce/) folder and single-product.php in plugin folder.
    All you have to do is put both template in your theme’s woocommerce folder(it is the proper way to customize original code).

    still if it does not work then try to replace your code

    woocommerce_get_template_part( ‘content’, ‘single-product’ );

    with this.
    wc_get_template_part( ‘content’, ‘single-product’ );

  2. Replying to helgatheviking input. As mentioned the is_product_category() call refers to a categories archive page and not a product assigned to the category type. Here’s my working example for a composite product. Replace YourCategorywith the slug of your category

    <?php
        if (has_term('YourCategory', 'product_cat')) {
            echo 'composite';
            wc_get_template_part( 'content', 'YourCategory' );
        }else{
            echo 'default';
            wc_get_template_part( 'content', 'single-product' );
        } ?>
    

Comments are closed.