• Resolved Carl Brubaker

    (@imconfused4sure)


    My sites with WooCommerce that use the default single-product.php are missing the header and footer because it is pulling the wp-includes/template-canvas.php even though I am not using a block theme.

    I tried this

    function action_remove_block_templates()
        {
        	remove_theme_support('block-templates');
        }
        add_action('after_setup_theme', 'action_remove_block_templates');

    but it didn’t work. I also tried creating a single-product.php in the theme and that did not work either.

    How can I force WordPress to not look for HTML template parts?

    I did try switching to the theme twentytwentyone and it worked correctly

    • This topic was modified 2 years, 3 months ago by Carl Brubaker.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Carl Brubaker

    (@imconfused4sure)

    UPDATE:

    I have been digging through this and have found that self::has_block_template( 'single-product' ) is returning true even though I am not using a block theme.

    file includes/class-wc-template-loader.php line 167.

    When I changed this to return false it rendered correctly.

    Mirko P.

    (@rainfallnixfig)

    Hi @imconfused4sure,

    I did try switching to the theme twentytwentyone and it worked correctly

    This basically means there is something that needs to be fixed on your theme. Thus, you’d be best placed to reach out to the theme author for further assistance with this.

    If you’re a developer and developed your own theme you can also visit the official WooCommerce Facebook Group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    When I changed this to return false it rendered correctly.

    It seems I missed your update here. If it’s resolved you can close the thread otherwise it will be a good idea to get more inputs from other developers in the channels mentioned above.

    Cheers.

    • This reply was modified 2 years, 3 months ago by Mirko P..
    Thread Starter Carl Brubaker

    (@imconfused4sure)

    Yes, I understand that there is something in the theme that needs corrected. I was hoping for some insights into what I need to code to get it to not recognize the .html templates.

    I will dig through the function more to see if I can figure out how to get it to return false.

    Thanks

    Thread Starter Carl Brubaker

    (@imconfused4sure)

    I found the proper filter to resolve the issue.

    function filter_no_woocommerce_block_templates($has_template)
    {
    	return false;
    }
    
    function action_add_filter_no_woocommerce_block_templates()
    {
    	add_filter('woocommerce_has_block_template', 'filter_no_woocommerce_block_templates', 10, 1);
    }
    add_action('template_include', 'action_add_filter_no_woocommerce_block_templates');
    Thread Starter Carl Brubaker

    (@imconfused4sure)

    Ignore code above. Use this instead.

    function action_remove_block_templates()
    {
    	remove_theme_support('block-templates');
    }
    add_action('after_setup_theme', 'action_remove_block_templates', 15);
    
    function filter_no_woocommerce_block_templates($has_template)
    {
    	return false;
    }
    
    function filter_add_filter_no_woocommerce_block_templates($template)
    {
    	add_filter('woocommerce_has_block_template', 'filter_no_woocommerce_block_templates', 10, 1);
    	return $template;
    }
    add_filter('template_include', 'filter_add_filter_no_woocommerce_block_templates',10, 1);

    Hi @imconfused4sure!

    Glad to hear you found a solution! Thanks for sharing it with everybody 🙂

    I’ll mark this thread as resolved now. If you have any further questions, I recommend creating a new one.

    Cheers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WP5.9/WooCommerce defaulting to template-canvas.php’ is closed to new replies.