Woocommerce - overriding the template through a plugin

前端 未结 3 2061
南旧
南旧 2021-01-14 16:09

I have a question: is there a way to override WooCommerce\'s default template through a plugin the same way you\'d do it with a theme? I have this code:

Clas         


        
3条回答
  •  清歌不尽
    2021-01-14 16:55

    You should try adding this code before your // Use default template code:

    if( $template_name == '{template part name}') {
         $template = $plugin_path . $template_name;
    }
    

    In my case {template part name} was global/quantity-input.php

    You can find out your exact template part names by temporary adding this line to your code:

    print_r($template_name);
    

    I know it's a bit late for answer here but maybe it will be useful for someone else. And keep in mind woocommerce_locate_template is depricated. So there is probably more 'up to date' solution somewhere out there.

提交回复
热议问题