【问题标题】:Add a custom class to woocommerce recent product reviews div将自定义类添加到 woocommerce 最近的产品评论 div
【发布时间】:2020-08-07 06:00:45
【问题描述】:

我正在尝试向位于 content-widget-reviews.php<div class="star-rating"> 添加一个类(在 woocommerce 模板中) 显示在这里: <?php echo wc_get_rating_html( intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ) ); ?>

我想让我的模板与 Bootstrap 4 一起工作(见下面的大写) float right needs to be removed 对比 wanted result

我在下面尝试了这个解决方案,但是它在整个模板上添加了类(我只想将这个类添加到小部件区域)

// Widget review Stars
function myfuntion_wc_get_rating_html($html) {
// Replace link classes
$html = str_replace('<div class="star-rating"', '<div class="star-rating float-none text-primary"', $html);
return $html;
}
add_filter("woocommerce_product_get_rating_html", "myfuntion_wc_get_rating_html")

;

有没有办法直接在这段代码上添加我的自定义类?

<?php echo wc_get_rating_html( intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ) ); ?>

谢谢

附:我想避免使用 Jquery 和 CSS

【问题讨论】:

    标签: php wordpress woocommerce bootstrap-4


    【解决方案1】:

    您是否尝试过替换主题中的 WooCommerce 模板,如https://docs.woocommerce.com/document/template-structure/ 所述?

    使用覆盖以升级安全的方式编辑文件。复制模板 进入主题中名为 /woocommerce 的目录,保持不变 文件结构,但删除 /templates/ 子目录。

    【讨论】:

    • 感谢您的回复。是的,我做到了,但我无法将我想要的类添加到代码中
    猜你喜欢
    • 2021-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 2015-05-27
    相关资源
    最近更新 更多