php - Wordpress Woocommerce hook woocommerce_before_main_content not working -


i need add information category in woocommerce category page. added following code in theme functions.php, didn't work. not first echo use debug if hook working displayed. doing wrong?

//adiciona informações da categoria na página de categoria  function brg_informacoes_de_categoria(){     echo 'it works!';     if(is_product_category()){              $product_cats = wp_get_post_terms( get_the_id(), 'product_cat' );             $single_cat = array_shift( $product_cats );               $field_cod = get_field('codigo', $single_cat->id);             $field_teatro = get_field('teatro', $single_cat->id);             $field_info = get_field('informações', $single_cat->id);             $field_cidade = get_field('cidade', $single_cat->id);             $field_estado = get_field('estado', $single_cat->id);             $field_inicio = get_field('inicio', $single_cat->id);             $field_termino = get_field('termino', $single_cat->id);              echo 'código evento' . $field_cod . '<br >';             echo 'teatro' . $field_teatro . '<br >';             echo 'informações' . $field_info . '<br >';             echo 'cidade' . $field_cidade . '<br >';             echo 'estado' . $field_estado . '<br >';             echo 'de ' . $field_inicio . ' ' . $field_termino . '<br >';             }  add_action('woocommerce_before_main_content','brg_informacoes_de_categoria', 2 ); 

it appears you've overwritten woocommerce single-product.php template in theme, , single-product.php file lacking following code:

do_action( 'woocommerce_before_main_content' ); 

so have add line somewhere in single-product.php file in woocommerce directory of theme.

another option delete single-product.php file - woocommerce use default single-product.php file, contains line.

update

you're trying hook function early. try using priority 10 or higher when attach function.

to this, replace following line:

add_action('woocommerce_before_main_content','brg_informacoes_de_categoria', 2 ); 

with following:

add_action('woocommerce_before_main_content','brg_informacoes_de_categoria', 10 ); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -