plugins – Different custom templates for product category

Question

I want to have multiple different templates depending on product category. Looking at Template for different category on woocommerce product I sort of got it working

I’ve copied single-product.php into theme-folder/woocommerce/ and have updated the code to be

            <?php the_post(); ?>

            <?php
                //wc_get_template_part( 'content', 'single-product' );
            if( has_term( 'course', 'product_cat' ) ) {
                wc_get_template_part( 'content', 'single-product-course' );
            } else {
                wc_get_template_part( 'content', 'single-product' );
            }

            ?>

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

Then I’ve created two files in theme-folder/woocommerce/content-single-product.php and content-single-product-course.php

Both seem to display fine when viewing the individual products, however, viewing the product with the course the template displays an error, (although it does still render the HTML)

Warning: include(/site/wp-content/plugins/woocommerce-bookings/templates/booking-form/.php): failed to open stream: No such file or directory in /site/wp-content/plugins/woocommerce/includes/wc-core-functions.php on line 345


#   Time    Memory  Function    Location
1   0.0009  413744  {main}( )   .../index.php:0
2   0.0010  415328  require( '/site/wp-blog-header.php' )   .../index.php:17
3   1.8879  63328264    require_once( '/site/wp-includes/template-loader.php' ) .../wp-blog-header.php:19
4   1.9015  63307352    include( '/site/wp-content/themes/dyfi-storefront-child/woocommerce/single-product.php' )   .../template-loader.php:106
5   1.9950  64097248    wc_get_template_part( ) .../single-product.php:44
6   1.9952  64098072    load_template( )    .../wc-core-functions.php:284
7   1.9954  64101152    require( '/site/wp-content/themes/dyfi-storefront-child/woocommerce/content-single-product-course.php' )    .../template.php:772
8   1.9970  64113712    do_action( )    .../content-single-product-course.php:62
9   1.9970  64114088    WP_Hook->do_action( )   .../plugin.php:470
10  1.9970  64114088    WP_Hook->apply_filters( )   .../class-wp-hook.php:327
11  2.0539  64450192    woocommerce_template_single_add_to_cart( )  .../class-wp-hook.php:303
12  2.0539  64450248    do_action( )    .../wc-template-functions.php:1667
13  2.0540  64450624    WP_Hook->do_action( )   .../plugin.php:470
14  2.0540  64450624    WP_Hook->apply_filters( )   .../class-wp-hook.php:327
15  2.0540  64451752    WC_Booking_Cart_Manager->add_to_cart( ) .../class-wp-hook.php:303
16  2.0554  64565880    wc_get_template( )  .../class-wc-booking-cart-manager.php:63
17  2.0558  64573392    include( '/site/wp-content/plugins/woocommerce-bookings/templates/single-product/add-to-cart/booking.php' ) .../wc-core-functions.php:345
18  2.0559  64573432    WC_Booking_Form->output( )  .../booking.php:41
19  2.0993  64632408    wc_get_template( )  .../class-wc-booking-form.php:400

0
colouredFunk 4 weeks 2021-08-31T04:42:21-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse