0

我正在尝试替换 woocommerce 文件中的一些文本,因此我需要在我的 functions.php 文件中创建一个钩子,以便当 woocommerce 更新时,它不会通过恢复到原始代码来损害我的网站。

我正在尝试替换这部分代码:

<h3><?php the_title(); ?></h3>

有了这个:

<div class="caption"><h5><?php the_title(); ?></h5>
  <div class="category-main-points"><?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
  </div>
</div>

这是原始文件中的部分代码:

<li <?php post_class( $classes ); ?>>

<?php do_action( 'woocommerce_before_shop_loop_item' ); ?>

<a href="<?php the_permalink(); ?>">

    <?php
        /**
         * woocommerce_before_shop_loop_item_title hook
         *
         * @hooked woocommerce_show_product_loop_sale_flash - 10
         * @hooked woocommerce_template_loop_product_thumbnail - 10
         */
        do_action( 'woocommerce_before_shop_loop_item_title' );
    ?>

    <h3><?php the_title(); ?></h3>

    <?php
        /**
         * woocommerce_after_shop_loop_item_title hook
         *
         * @hooked woocommerce_template_loop_price - 10
         */
        do_action( 'woocommerce_after_shop_loop_item_title' );
    ?>

</a>

<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>

</li>

到目前为止,这是我的钩子:

<?php
// Add text to content-product-cat to help with styling
add_action('woocommerce_before_subcategory_title', 'woohook_before_subcategory_title');

function woohook_before_subcategory_title() {
ob_start();

}

add_action('woocommerce_after_subcategory_title', 'woohook_after_subcategory_title');

function woohook_after_subcategory_title() {
 $subcategory_title = ob_get_clean();

}
?>

有任何想法吗?

4

1 回答 1

0

Woocommerce 允许您覆盖其模板,只需将原始文件复制到./wp-content/themes/my-theme/woocommerce/并编辑即可!

于 2013-04-22T11:45:32.923 回答