Hello,
this didn’t address the root cause of the issue, in fact it didn’t remove the warning at all.
Here’s the full Warning message:
Notice: is_page was called <strong>incorrectly</strong>. Conditional query tags do not work before the query is run. Before then, they always return false. Please see <a href="https://ww.wp.xz.cn/support/article/debugging-in-wordpress/">Debugging in WordPress</a> for more information. (This message was added in version 3.1.0.)
Note that is_page is called inside the is_account_page function.
The issue is caused because is_account_page is called before the template_redirect action is executed, and that’s the issue.
Conceptually you should check if template_redirect has been called before using is_account_page, which is defined in the previous step since WooCommerce is a plugin and loads before this plugin. So the function exists, but if somebody calls ‘woocommerce_currency_symbol’ before the $wp_query is initialized, it will throw the warning.
The problem with the code of the function is the following:
global $wp_query;
if (!isset($wp_query)) {
if (is_order_received_page() || is_account_page()) {
if (apply_filters('woocs_currency_symbol_on_order', false)) {
return $currency_symbol;
}
}
}
Why is it an issue?
Because when the $wp_query is not set, both ‘is_order_received_page’ and ‘is_account_page’ use the ‘is_page’ core function which is defined in the wp-includes/query.php as this:
function is_page( $page = '' ) {
global $wp_query;
if ( ! isset( $wp_query ) ) {
_doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1.0' );
return false;
}
return $wp_query->is_page( $page );
}
This means that if the $wp_query is not defined when we call is_page, the notice of doing it wrong will be thrown, and both functions will return false, making the code in the nested if statements not execute.
A possible solution would be changing the code to:
global $wp_query;
if (!isset($wp_query)) {
return $currency_symbol;
}
Let me know if this was helpful.