Woo Conditionals on init

I’m trying to add the title above the breadcrumbs. My questions is why WooCommerce Conditionals work better on template_redirect but don’t work on init. For example:

/** Woo General Init **/
function woo_general_init() {
    echo ( is_product() ) ? 'True' : 'False';

    if( is_product() ) {
        add_action( 'woocommerce_before_main_content', 'woocommerce_template_single_title', 10 );
        add_action( 'woocommerce_before_main_content', 'woocommerce_template_single_excerpt', 11 );
    }
}
add_action( 'init', 'woo_general_init' );

Evaluates to False at the top of my document when viewing a single WooCommerce product. On the other-hand, if I change init to template_redirect the conditional outputs True:

Read More
/** Woo General Init **/
function woo_general_init() {
    echo ( is_product() ) ? 'True' : 'False';

    if( is_product() ) {
        add_action( 'woocommerce_before_main_content', 'woocommerce_template_single_title', 10 );
        add_action( 'woocommerce_before_main_content', 'woocommerce_template_single_excerpt', 11 );
    }
}
add_action( 'template_redirect', 'woo_general_init' );

Why do I get “False” when hooked into init but “True” on template_redirect? What’s the best hook to run WooCommerce conditional data?

Related posts

1 comment

Comments are closed.