从Woocommerce单一产品评论标题中删除产品标题



我试图在我的function.PHP文件中使用PHP,在产品收到评论之前/之后,将产品标题从产品页面上的Wooccommerce评论标题中删除。

目前,默认的Wooccommerce评论标题如下:

  • (在任何评论之前(:第一个评论[产品标题]
  • (在任何审查之后(:对[产品名称]进行1次审查

我如何删除在任何一种情况下使用的产品标题,并简单地将产品评论标题更改为静态";创建评论";不管是否有评论?

我相信这一切都发生在singleproducts-reviews.php中。不幸的是,我对php的精通程度还不够。

您需要将single-product-reviews.php从wp-contents/plugins/woocomerce/templates/复制到wp-content/themes/youractivetheme/woocommerce/single-product-reviews.php,如果您的主题没有woocomerce文件夹,请创建一个文件夹并将该文件粘贴到其中。这不会在下次更新时覆盖更改。

要小心,如果你使用的是一些专业主题或非自定义开发的主题,那么就使用儿童主题(在这里你可以了解更多关于儿童主题的信息https://developer.wordpress.org/themes/advanced-topics/child-themes/)然后按照您的childtheme/woocommerce/singleproduct.reviews.php文件的目录结构。

一旦复制到那里,就需要编辑该文件。转到34号线的某个位置并替换以下代码

$reviews_title = sprintf( esc_html( _n( '%1$s review for %2$s', '%1$s reviews for %2$s', $count, 'woocommerce' ) ), esc_html( $count ), '<span>' . get_the_title() . '</span>' );

带有

$reviews_title = esc_html( 'Create a review', 'woocommerce' );

或者,您可以在活动主题的functions.php文件中使用woococommerce_reviews_title过滤器。

add_filter("woocommerce_reviews_title", function( $reviews_title, $count, $product )
{
return $reviews_title = esc_html( 'Create a review', 'woocommerce' );
});

现在要更改成为第一个审查[产品标题]更改以下代码[行#75]

'title_reply'         => have_comments() ? esc_html__( 'Add a review', 'woocommerce' ) : sprintf( esc_html__( 'Be the first to review &ldquo;%s&rdquo;', 'woocommerce' ), get_the_title() ),

带有

'title_reply'         => have_comments() ? esc_html__( 'Create a review', 'woocommerce' ) : esc_html__( 'Create a review', 'woocommerce' ),

这应该对你有用。

最新更新