woocommerce类别和子类别标题钩子

我想修改某个类别的默认标题和woocommerce的相对子类别。我发现了这个问题,但这只会从类别中删除标题。


使用检查器,我能够找到这个css类,但我无法理解哪个钩子负责呈现类别和子类别的标题。.woocommerce-loop-category__title


任何人都可以帮我吗?


这是我的代码


function theme_woocommerce_loop_category_title()

  {

    if( is_product_category() ):

    ?>

      <h2 class=""><?php the_title(); ?></h2>

    <?php

    endif;

  }

  add_action( 'woocommerce_template_loop_category_title', 'theme_woocommerce_loop_category_title', 10 );


  remove_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title', 10 );



DIEA
浏览 119回答 1
1回答

慕哥6287543

woocommerce_shop_loop_subcategory_title这个钩子负责类别标题,所以如果你想更新你的类别标题,那么你可以这样做function woocommerce_template_loop_category_title_override( $category ) { ?>&nbsp; &nbsp; <h2 class="woocommerce-loop-category__title">&nbsp; &nbsp; &nbsp; &nbsp; <?php&nbsp; &nbsp; &nbsp; &nbsp; echo esc_html( $category->name ); //Update your title which you want to update here&nbsp; &nbsp; &nbsp; &nbsp; if ( $category->count > 0 ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo apply_filters( 'woocommerce_subcategory_count_html', ' <mark class="count">(' . esc_html( $category->count ) . ')</mark>', $category );&nbsp; &nbsp; &nbsp; &nbsp; } ?>&nbsp; &nbsp; &nbsp; &nbsp; </h2><?php}add_action( 'woocommerce_shop_loop_subcategory_title', 'woocommerce_template_loop_category_title_override', 10 );
打开App,查看更多内容
随时随地看视频慕课网APP