• Resolved iain-g

    (@iain-g)


    Using Woocommerce 2.4.10 in a local development. I’ve found instructions on overriding single product template: in my theme’s woocommerce folder for overrides, if I edit ‘content-single-product.php’ the changes take effect, so I know overrides are in the right place.

    What I want eventually is a separate template for glass products, so I’ve saved a template called ‘content-single-product-crystal.php’ (a slightly tweaked ‘content-single-product.php’). Then in ‘single-product.php’, just to check it’s working at first I’ve changed

    <?php wc_get_template_part( 'content', 'single-product' ); ?>

    into

    <?php wc_get_template_part( 'content', 'single-product-crystal' ); ?>

    but my crystal template is ignored.

    I’ve tried doing the same changes to the original woocommerce ‘single-product.php’ but that doesn’t work either (restored that file to its original state now). I’ve even tried deleting other chunks of ‘theme>woocommerce>single-product.php’ to see if the file’s being used, but that does nothing either.

    In ‘admin > woocommerce > system status’ at the bottom where it lists template overrides it lists ‘single-product.php’ and ‘content-single-product.php’, but should it also list my ‘content-single-product-crystal.php’ ? (it doesn’t).

    Must be going mad but can’t see what I’m doing wrong… Sorry I can’t post a link, as it’s not live yet.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter iain-g

    (@iain-g)

    I’ve dug around further, and single-product.php – both my override and the core woo commerce version are ignored – I’ve even deleted them completely. Instead the woocommerce functions.php file sets the template on line 339

    wc_get_template_part( 'content', 'single-product' );

    editing this gets it to look at my template file, though I obviously don’t want to edit that functions file – so how can I override that?

    Thread Starter iain-g

    (@iain-g)

    OK, talking to myself here, but I’ve added

    if ( ! function_exists( 'woocommerce_content' ) ) {
    	function woocommerce_content() {
    		if ( is_singular( 'product' ) ) {
    			while ( have_posts() ) : the_post();
    				wc_get_template_part( 'content', 'single-product-book' );
    			endwhile;
    		}
    	}
    }

    to my themes functions.php file which works – but how do I target a product category?

    Thread Starter iain-g

    (@iain-g)

    Cracked it – in functions.php of my theme:

    if ( ! function_exists( 'woocommerce_content' ) ) {
    	function woocommerce_content() {
    		if ( has_term( 'CATEGORY-NAME', 'product_cat' ) ) {
    			while ( have_posts() ) : the_post();
    				wc_get_template_part( 'content', 'single-product-CATEGORY-NAME' );
    			endwhile;
    		}
    		else {
    			while ( have_posts() ) : the_post();
    				wc_get_template_part( 'content', 'single-product' );
    			endwhile;
    		}
    	}
    }

    thebigtine

    (@josephbydesign)

    Just so you know your “talking to yourself” really helped me fix my problems!

    I also want to thank you for “talking to yourself”. You just helped me fix a problem I have been stuck on for days! So it is much appreciated. Thanks again! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘single-product.php override is ignored’ is closed to new replies.