I've been trying to apply a filter to WooCommerce from inside my own custom plugin but whatever I do, the filter is not firing.
The commonly found solutions online don't work. I've tried:
- Overwrite wordpress theme page by plugin
- Custom templates in Woocommerce 3
- https://www.damiencarbery.com/2017/01/override-woocommerce-template-files-in-a-plugin/
- https://javorszky.co.uk/2017/09/07/where-do-you-redeclare-a-template/
I've also tried to attach the filter to various action points (init, plugins_loaded) and various priorities (10, 20, 999).
To test I've created a simple one-page plugin. When the filter fires it should write to error_log. The file is in /wp-content/plugins/plugintest.php
<?php
/*
* Plugin Name: Plugin TEST
* Description: A simple plugin to test
* Version: 1.0
**/
function my_test_get_template( $template, $template_name, $args ) {
error_log('working ...... FILTER .... ');
return $template;
}
error_log('working ... ');
add_filter( 'woocommerce_locate_template', 'my_test_get_template', 20, 3);
However the error_log inside the filter never gets written, the output is simply
[15-Oct-2019 16:20:52 UTC] working ...
I don't understand why the code is not working. I know that WooCommerce is active and working as the other code I wrote (which extends the WC_EMAIL class) is fine. And I can filter "woocommerce_email_classes" without any issues, that's also working. But the template path won't fire. Anything obvious I'm doing wrong?