Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用钩子替换wordpress文件中的文本_Php_Wordpress_Hook_Woocommerce - Fatal编程技术网

Php 用钩子替换wordpress文件中的文本

Php 用钩子替换wordpress文件中的文本,php,wordpress,hook,woocommerce,Php,Wordpress,Hook,Woocommerce,我正在尝试替换woocommerce文件中的一些文本,因此我需要在functions.php文件中创建一个钩子,这样当woocommerce更新时,它不会因为还原到原始代码而损害我的站点 我正在尝试替换代码的这一部分: <h3><?php the_title(); ?></h3> 为此: <div class="caption"><h5><?php the_title(); ?></h5> <di

我正在尝试替换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();

}
?>


有什么想法吗?

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

谢谢diggy,我不知道。嗨,diggy,这似乎对很多文件都有效,但我刚刚编辑了empty-cart.php文件,它不起作用。原始文件位置在woocomece/templates/cart中,我想这似乎对很多文件都有效,但我刚刚编辑了empty-cart.php文件,它不起作用。原始文件位置在woocomece/templates/cart中,我已经向我的woocome文件夹添加了一个新文件,如前面提到的其他文件,如content-product_cat.php,它们可以工作,但empty-cart.php不行,有什么想法吗?我想你必须尊重文件夹结构,所以试着把它放到
/wp content/themes/my theme/woocommerce/cart/
谢谢diggy,我以为我已经做到了,但我把它放到了templates/cart而不是cart