• Hi there –

    I’m trying to use two different template parts based on what category a product is in for the single-product.php template in WooCommerce. I have created the proper directory in my theme and have copied over the necessary files to my theme folder. Here is the code:

    <?php
    /**
     * The Template for displaying all single products.
     *
     * Override this template by copying it to yourtheme/woocommerce/single-product.php
     *
     * @author 		WooThemes
     * @package 	WooCommerce/Templates
     * @version     1.6.4
     */
    
    if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    get_header( 'shop' ); ?>
    
    		<?php while ( have_posts() ) : the_post(); ?>
    
    			<?php if ( is_product_category( 'horizontal' ) ) { ?>
    				<?php wc_get_template_part( 'content', 'single-product-horizontal' ); ?>
    			<?php } else { ?>
    				<?php wc_get_template_part( 'content', 'single-product' ); ?>
    			<?php } ?>
    
    		<?php endwhile; // end of the loop. ?>
    
    	<?php
    		/**
    		 * woocommerce_sidebar hook
    		 *
    		 * @hooked woocommerce_get_sidebar - 10
    		 */
    		do_action( 'woocommerce_sidebar' );
    	?>
    
    <?php get_footer( 'shop' ); ?>

    My PHP skills are limited so iIm not sure why the conditional statement isn’t working but the front end is only calling the default ‘content-single-product.php’

    Any help is appreciated

    Thanks

    BC

  • The topic ‘WooCommerce Single Product Different Templates for Different Categories’ is closed to new replies.