Skip to content

Instantly share code, notes, and snippets.

@carasmo
Last active July 11, 2016 22:14
Show Gist options
  • Save carasmo/0cd5e3383920cb2dd6be to your computer and use it in GitHub Desktop.
Save carasmo/0cd5e3383920cb2dd6be to your computer and use it in GitHub Desktop.
For Genesis Child Theme (or any child theme, or change the path on the load_template if a parent theme). These instructions will help you show a different single product template page based on the category slug. If this was helpful, saved you hours of time, please consider a small donation via PayPal to christinabeymer@gmail.com.
<?php
/** ====================================================================================
* Return single product template page based on category slug
==================================================================================== **/
/** ========== Instructions ========================================================
* If this is helpful, consider a small donation via PayPal to christinabeymer@gmail.com
* 1. Copy your existing child-theme/woocommerce/single-product.php and rename it
* default-single.php. Do nothing on the default-single.php.
* Put default-single.php in your child-theme/woocommerce/ directory
* 2. Replace the contents of the original single-product.php with the contents of
* this gist minus the instructions. Use the correct tools
* for this -- good code editor and ftp or shell access.
==================================================================================== **/
global $woocommerce;
// 'category-slug' is your slug
if ( has_term( 'category-slug', 'product_cat' ) ) :
$file = 'woo-test-single.php'; // the category specific template
else: // not term show default
$file = 'default-single.php'; // the default single template
endif;
load_template( get_stylesheet_directory() . '/woocommerce/'.$file );
//genesis(); not required
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment