How to Override ‘single-product.php’ Successfully?
-
Hi all,
Just starting my WooCommerce Store journey (and WP for that matter) and can’t figure out why the shop’s header [store nav area] isn’t showing?
The entire store functions as expected, but when I attempt to override single-product.php – and I mean a copy without any modifications made to it, yet – the product page shows (with some small styling issues) but the header, sidebar, footer sections do not appear?
The caveat is – I’m trying to do it from a custom plugin with:
function load_custom_product_template($template) { global $post; $product = wc_get_product($post->ID); if ($product && $product->get_type() === 'extended') { $custom_template = plugin_dir_path(__FILE__) . 'woocommerce/single-product.php'; if (file_exists($custom_template)) { return $custom_template; } } return $template; } add_filter('template_include', 'load_custom_product_template');
So, other than the single-product.php – do I have to copy a ‘header.php’ & ‘footer.php’ from somewhere – I can’t find anything header/footer related in woocommerce and after searching the forum, people have mentioned it’s controlled by the theme anyways; which does appear to be correct, as Query Monitor lists these under templates used:
\wordpress\wp-includes\theme-compat\header.php | footer.php
-but even when attempting to override the template via my theme (with the plugin disabled), i.e.:
…themes\twentytwentyfour\woocommerce\single-product.php OR …themes\twentytwentyfour\woocommerce\single-product\single-product.php [tried both]
It still doesn’t have any effect.…so how does WooCommerce do it then? Many thanks for any help or advice in advance, Cheers Dyr
Versions: WP: 6.5.3? |? Woocommerce 8.8.3? |? Theme: twentytwentyfour
- The topic ‘How to Override ‘single-product.php’ Successfully?’ is closed to new replies.