Sometimes you may run into a case where a php function that WooCommerce has defined doesn’t work as expected.
This could be due to WooCommerce not being fully loaded or something is not yet set up internally (WP query or WC query).
You can try hooking your function in one of the following hooks. It is quite possible for the init hook to work for you and not the others.
add_action( 'init', 'your_function_', 50 );
add_action( 'wp_loaded', 'your_function_' );
add_action( 'woocommerce_init', 'your_function_' );
add_action( 'woocommerce_loaded', 'your_function_' );
Here’s a related post on Stack Overflow regarding the is_shop() WooCommerce function.