php - woocommerce_locate_template filter from plugin instead of theme -
i found article on using plugins instead of themes override woocommerce template: https://www.skyverge.com/blog/override-woocommerce-template-file-within-a-plugin/
it seems work, it's not working templates in root of woocommerce/templates directory (like single-product.php or content-single-product.php).
to illustrate, have filter:
add_filter('woocommerce_locate_template', array($this, 'woocommerce_locate_template'), 10, 3); calling function:
public function woocommerce_locate_template($template, $template_name, $template_path) { global $woocommerce; al_log('looking ' . $template . ', ' . $template_name . ', ' . $template_path); $_template = $template; if (! $template_path) $template_path = $woocommerce->template_url; $plugin_path = $this->my_plugin_path() .'/woocommerce/'; //look within passed path within theme. priority $template = locate_template( array( $template_path . $template_name, $template_name, ) ); //modification: template plugin, if exists if (!$template && file_exists($plugin_path . $template_name)) $template = $plugin_path . $template_name; //use default template if (! $template) { $template = $_template; } return $template; } it results in these log lines:
[davetbo@dev wp-content]$ [05-feb-2016 17:10:46 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/global/breadcrumb.php, global/breadcrumb.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/sale-flash.php, single-product/sale-flash.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/product-image.php, single-product/product-image.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/product-thumbnails.php, single-product/product-thumbnails.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/title.php, single-product/title.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/rating.php, single-product/rating.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/price.php, single-product/price.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/short-description.php, single-product/short-description.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/meta.php, single-product/meta.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/share.php, single-product/share.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/tabs/tabs.php, single-product/tabs/tabs.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/tabs/description.php, single-product/tabs/description.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/tabs/additional-information.php, single-product/tabs/additional-information.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/product-attributes.php, single-product/product-attributes.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/up-sells.php, single-product/up-sells.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/single-product/related.php, single-product/related.php, woocommerce/ [05-feb-2016 17:10:47 utc] looking /var/www/html/wp-content/plugins/woocommerce/templates/global/sidebar.php, global/sidebar.php, woocommerce/ as can see, never goes looking in root of woocommerce/templates directory. thoughts why filter doesn't work single-product.php or content-single-product.php?
i have woocommerce folder in root of plugin folder , inside there's single-product.php file die statement near top, should see if it's working. did put same single-product.php file in woocommerce folder in theme , works there, not plugin. there different hook should using? please advise.
Comments
Post a Comment