caskew2154
11/18/2019 - 9:39 AM

Multiple Product Page

Add Multiple Product Page Templates

Flatsome Child > WooCommerce Folder

  • single-product.php > Conditional to point to individual templates. has_term codex
- template-choice.php > Responsible for loading in individual template content. Alter line 36 - wc_get_template_part( 'content', 'change-this' ); to match created content-single-product file. This will automatically add "content-" as a prefix, so the file below must be prefixed with 'content-'
  • content-single-product.php > Load in a unique UX Block for the chosen page.
    Change Block ID on line 37
<?php
if( has_term( array( 'cat-one', 'cat-two'), 'product_cat' ) ){
  wc_get_template_part( 'template-choice-one.php' );
} 
else if( has_term( array( 'cat-three' ), 'product_cat' ) ){
  wc_get_template_part( 'template-choice-two.php' );
} 
else {
  wc_get_template_part( 'template-choice-three.php' );
}
?>
<?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' );

do_action('flatsome_before_product_page');

?>

	<?php
		/**
		 * woocommerce_before_main_content hook
		 *
		 * @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
		 * @hooked woocommerce_breadcrumb - 20
		 */
		do_action( 'woocommerce_before_main_content' );
	?>

		<?php while ( have_posts() ) : the_post(); ?>

			<?php
          if(get_theme_mod('product_layout') == 'custom') {
            wc_get_template_part( 'content', 'single-product' );
          }
      ?>

		<?php endwhile; // end of the loop. ?>

	<?php
		/**
		 * woocommerce_after_main_content hook
		 *
		 * @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
		 */
		do_action( 'woocommerce_after_main_content' );
	?>

<?php

do_action('flatsome_after_product_page');
<?php
/**
 * The template for displaying product content in the single-product.php template
 *
 * Override this template by copying it to yourtheme/woocommerce/content-single-product.php
 *
 * @author        WooThemes
 * @package       WooCommerce/Templates
 * @version       3.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}
?>
<div class="container">
	<?php
	/**
	 * Hook Woocommerce_before_single_product.
	 *
	 * @hooked wc_print_notices - 10
	 */
	do_action( 'woocommerce_before_single_product' );
	if ( post_password_required() ) {
		echo get_the_password_form(); // WPCS: XSS ok.

		return;
	}
	?>
</div><!-- /.container -->
<div id="product-<?php the_ID(); ?>" <?php post_class(); ?>>

	<div class="custom-product-page">

		<?php
		if ( get_theme_mod( 'product_custom_layout' ) ) :
			echo do_shortcode( '[block id="buying-product-page"]' );
			?>
			<div id="product-sidebar" class="mfp-hide">
				<div class="sidebar-inner">
					<?php
					do_action( 'flatsome_before_product_sidebar' );
					/**
					 * woocommerce_sidebar hook
					 *
					 * @hooked woocommerce_get_sidebar - 10
					 */
					if ( is_active_sidebar( 'product-sidebar' ) ) {
						dynamic_sidebar( 'product-sidebar' );
					} elseif ( is_active_sidebar( 'shop-sidebar' ) ) {
						dynamic_sidebar( 'shop-sidebar' );
					}
					?>
				</div><!-- .sidebar-inner -->
			</div>
			<?php
		else :
			echo '<p class="lead shortcode-error">Create a custom product layout by using the UX Builder. You need to select a Block as custom product layout and then open it in the UX Builder from the product page.</p>';
		endif;
		?>

	</div>

	<?php do_action( 'woocommerce_after_single_product' ); ?>

</div>